SRL Archive - C#/Visual Basic Help and Tutorials

I'm a VB Noooooooooobyyyy


IEatJ00erBaybees

2008-01-19 20:24:39

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

2008-01-19 20:29:24

That is very confusing…. Or thats a bad way to code a stop watch, I think.

IEatJ00erBaybees

2008-01-19 20:35:53

From: JuKKa
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

2008-01-19 20:38:07

Dim = Variables

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

IEatJ00erBaybees

2008-01-19 21:03:32

So how do you suggest I make this if this guys way SUCKS?

R0b0t1

2008-01-19 23:44:32


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

2008-01-20 11:35:22

From: R0b0t1

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

2008-01-20 11:57:52

*Cough* Outdated *Cough*

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

IEatJ00erBaybees

2008-01-20 12:12:22

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

2008-01-20 12:32:16

Eww. Vb.

JuKKa

2008-01-20 12:34:28

Val()

FEAR

2008-01-20 12:37:10

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

2008-01-20 12:41:55

What do you mean, Val()? What will I do with it?

R0b0t1

2008-01-20 15:07:54


lblOut = String(Int(lblVal1) + Int(lblVal2))

IEatJ00erBaybees

2008-01-20 18:27:09

So lblAns = String(Int(txtNum1.text) + Int(txtNum2.text)) ???

R0b0t1

2008-01-20 20:33:29

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

2008-01-21 00:04:31

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

2008-01-21 01:29:22

Uhh… No.


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

lblAns.text = String(sngAnswer)

IEatJ00erBaybees

2008-01-25 23:08:00

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

2008-01-26 11:03:53

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

2008-01-26 21:33:44

From: R0b0t1
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

2008-01-26 23:13:00

I'd pick VB, as it has more than Delphi. Essentially, the languages are almost interchangeable, but try to stay away from .net.

IEatJ00erBaybees

2008-01-26 23:52:44

But then again, I know a lot of Delphi functions, don't I?

R0b0t1

2008-01-27 13:00:01

Yer, but you couldn't use anything like FindColor without making it.

insanomano

2008-05-25 17:45:03

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

2008-05-26 09:33:08

Gravedigger.

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

Zigon

2008-06-09 17:49:12

What's the difference between vb and .net? And, why are you dimming as "varient type" not long, integer,…