PDA

View Full Version : I'm a VB Noooooooooobyyyy



IEatJ00erBaybees
01-20-2008, 01:24 AM
Well, you heard it from me. I'm a VB Noob. So I found a tutorial on download.com and we're making a stop watch, but I don't really understand how the variables work on here. Here is all the code. The download to it is:

http://www.download.com/3001-2251_4-10508664.html


Option Explicit On

Public Class frmStopWatch


Dim StartTime As VariantType
Dim EndTime As VariantType
Dim ElapsedTime As VariantType

Private Sub cmdStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStart.Click
'Establish and print starting time
StartTime = VariantType.Integer
lblStart.Text = Format(StartTime, "hh:mm:ss")
lblEnd.Text = ""
lblElapsed.Text = ""
End Sub

Private Sub cmdEnd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEnd.Click
'Find the Ending Time, Compute the Elapsed Time
'Put Both Values in Label Boxes
EndTime = VariantType.Integer
ElapsedTime = EndTime - StartTime
lblElapsed.Text = Format(EndTime, "hh:mm:ss")
lblElapsed.Text = Format(ElapsedTime, "hh:mm:ss")
End Sub

Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
End
End Sub

End Class

Did I set all this stuff up right?

Thanks.

JuKKa
01-20-2008, 01:29 AM
That is very confusing.... Or thats a bad way to code a stop watch, I think.

IEatJ00erBaybees
01-20-2008, 01:35 AM
That is very confusing.... Or thats a bad way to code a stop watch, I think.

That's what they were talking about. Dim's and Statics and Explicit's and Options...I am just lost.

JuKKa
01-20-2008, 01:38 AM
Dim = Variables

Option Explicit On = if i remember correctly it just gives more detailed error reports if u have a compile error.

IEatJ00erBaybees
01-20-2008, 02:03 AM
So how do you suggest I make this if this guys way SUCKS?

R0b0t1
01-20-2008, 04:44 AM
Option Explicit On

Public Class frmStopWatch


Dim StartTime As Integer
Dim EndTime As Integer
Dim ElapsedTime As Integer

Private Sub cmdStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStart.Click
'Establish and print starting time
lblStart.Text = Format(StartTime, "hh:mm:ss")
End Sub

Private Sub cmdEnd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEnd.Click
'Find the Ending Time, Compute the Elapsed Time
'Put Both Values in Label Boxes
ElapsedTime = EndTime - StartTime
lblElapsed.Text = Format(ElapsedTime, "hh:mm:ss")
End Sub

End Class

IEatJ00erBaybees
01-20-2008, 04:35 PM
Option Explicit On

Public Class frmStopWatch


Dim StartTime As Integer
Dim EndTime As Integer
Dim ElapsedTime As Integer

Private Sub cmdStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStart.Click
'Establish and print starting time
lblStart.Text = Format(StartTime, "hh:mm:ss")
End Sub

Private Sub cmdEnd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEnd.Click
'Find the Ending Time, Compute the Elapsed Time
'Put Both Values in Label Boxes
ElapsedTime = EndTime - StartTime
lblElapsed.Text = Format(ElapsedTime, "hh:mm:ss")
End Sub

End Class


Gotcha...They had a diagram in the thing which really helped me. It was like one box, which was the module. Inside the module it said X as Global Variable, Inside the module were two form boxes. In one form box there were two procedure type things, in one procedure thing, there was the Dim's. I know you don't get what I mean, but never mind, you guys already know VB. ;)

EDIT: Oy vey. I am just getting where it's supposed to display the time started saying "hh:mm:ss", not 11:53:30 or w/e time it is now.

Jason2gs
01-20-2008, 04:57 PM
*Cough* Outdated *Cough*

Delphi, C++, Java... Pretty much anything is better than VB6 nowadays ^_^

IEatJ00erBaybees
01-20-2008, 05:12 PM
I know Jason, but might as well start with the basics.

Could anybody tutor me?

I mean, right now I'm trying to make a calculator.
I've got the layout and all that, but I'm trying to get it so that txtNum1.Text + txtNum2.Text = Answer (which is a Dim as Single). Then the answer will display in a label in the bottom right.

But Text's are strings, so can I do a StrToInt type thing?

GoF
01-20-2008, 05:32 PM
Eww. Vb.

JuKKa
01-20-2008, 05:34 PM
Val()

FEAR
01-20-2008, 05:37 PM
You are not the only one:( I am a noob too:D I just started learning so I have no idea what that is:p

IEatJ00erBaybees
01-20-2008, 05:41 PM
What do you mean, Val()? What will I do with it?

R0b0t1
01-20-2008, 08:07 PM
lblOut = String(Int(lblVal1) + Int(lblVal2))

IEatJ00erBaybees
01-20-2008, 11:27 PM
So lblAns = String(Int(txtNum1.text) + Int(txtNum2.text)) ???

R0b0t1
01-21-2008, 01:33 AM
Yes...

As txtNum1 and txtNum2 are strings, you must convert them to integers to add them... Then you must turn it back to a string to place it on a label.

IEatJ00erBaybees
01-21-2008, 05:04 AM
Well, I don't think I do.

I made Dim sngAnswer As Single (For division and decimals)

And I am going to make sngAnswer = String(Int(txtNum1.text) + Int(txtNum2.text))

Oooo nvm.

So then I'll take String(Int(sngAnswer)) and then display that in lblAns.Text?

R0b0t1
01-21-2008, 06:29 AM
Uhh... No.



sngAnswer = Int(txtNum1.text) + Int(txtNum2.text)

lblAns.text = String(sngAnswer)

IEatJ00erBaybees
01-26-2008, 04:08 AM
Public Class frmCalc
Dim sngAnswer As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
sngAnswer = Int(txtNum1.Text) + Int(txtNum2.Text)
lblAns.Text = String(sngAnswer)
End Sub
End Class

I'm having a difficult time with this. I'm getting an error saying I can't have String because it's a class type and can't be used as an expression. Then it says ' expected, which sounds like it's looking for the string.

Do you guys just recommend Delphi or Pascal, since SCAR is basically delphi/pascal?

R0b0t1
01-26-2008, 04:03 PM
Delphi is Object Pascal, and improvement, so use it.

But as for your error, you must either have 'Option Explicit On' or I got the string converter name wrong. Try using Str("").

IEatJ00erBaybees
01-27-2008, 02:33 AM
Delphi is Object Pascal, and improvement, so use it.

But as for your error, you must either have 'Option Explicit On' or I got the string converter name wrong. Try using Str("").

OK. So I should ditch VB and just use Delphi which is basically like SCAR? What's the best compiler for that? What program should I make? That's what the hardest part is. What program should I make?

PS: It works :)

R0b0t1
01-27-2008, 04:13 AM
I'd pick VB, as it has more than Delphi. Essentially, the languages are almost interchangeable, but try to stay away from .net.

IEatJ00erBaybees
01-27-2008, 04:52 AM
But then again, I know a lot of Delphi functions, don't I?

R0b0t1
01-27-2008, 06:00 PM
Yer, but you couldn't use anything like FindColor without making it.

insanomano
05-25-2008, 09:45 PM
ok I am a noob at VB as well but I dont know what the proper version is, I have a express trial version, does this work properly for anything? Because I was reading a guys 98 tutorial and I actually learned a few things but I still dont know what version of VB I should use or if I should skip straight to Delphi or C ++???

TViYH
05-26-2008, 01:33 PM
Gravedigger.

But, you have Microsoft Visual Basic 2008 Express Edition. It is based off of .NET.

Zigon
06-09-2008, 09:49 PM
What's the difference between vb and .net? And, why are you dimming as "varient type" not long, integer,...