[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Hey guys, sorry for the "Homework help" thread. I'm

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 9
Thread images: 2

File: download.jpg (5KB, 232x145px) Image search: [Google]
download.jpg
5KB, 232x145px
Hey guys, sorry for the "Homework help" thread. I'm learning Visual Basic. I'll delete this thread as soon as I'm answered. I have to incorporate a TryParse method into a beginner program. I'm not exactly sure how to do that, this is my shitty code.

If any of you can help, I'd very much appreciate it:

Dim intNumberA As Integer ' To hold value in box A.
Dim intNumberB As Integer ' To hold value in box B.

' Clear any previously displayed message.
lblmessage.Text = String.Empty

' Retain the values from the textboxes.
intNumberA = CDbl(TextBoxA.Text)
intNumberB = CDbl(TextBoxB.Text)

'Compare the values
If intNumberA > intNumberB Then
lblmessage.Text = "Value A is greatest!"
Else
If intNumberA < intNumberB Then
lblmessage.Text = "Value B is greatest!"
Else
If intNumberA = intNumberB Then
lblmessage.Text = "Both values are equal!"
End If
End If
End If
>>
>>55744133
Replace CDbl with Double.TryParse?
>>
>>55744133
>>55744195

Okay, here you go, faggot. I don't know if it actually compiles or not. I did in a notepad.
Dim intNumberA As Integer ' To hold value in box A.
Dim intNumberB As Integer ' To hold value in box B.

' Clear any previously displayed message.
lblmessage.Text = String.Empty

' Retain the values from the textboxes.
Dim result As Boolean = Int32.TryParse(TextBoxA.Text, out intNumberA) && Int32.TryParse(TextBoxB.Text, out intNumberB)

'Compare the values
If (result) Then
If intNumberA > intNumberB Then
lblmessage.Text = "Value A is greatest!"
Else If intNumberA < intNumberB Then
lblmessage.Text = "Value B is greatest!"
Else If intNumberA = intNumberB Then
lblmessage.Text = "Both values are equal!"
End If
Else
lblmessage.Text = "Error!"
End if
>>
>>55744254
Replace "&&" with "And" though.
>>
>>55744254
Thanks, I had to change some things as I was getting syntax errors, but it works now. Thank you dude, would buy you a beer.

           Dim intNumberA As Integer   ' To hold value in box A.
Dim intNumberB As Integer ' To hold value in box B.

' Clear any previously displayed message.
lblmessage.Text = String.Empty

' Retain the values from the textboxes.
intNumberA = CDbl(TextBoxA.Text)
intNumberB = CDbl(TextBoxB.Text)

' Get the values.
If Integer.TryParse(TextBoxA.Text, intNumberA) Then
Integer.TryParse(TextBoxB.Text, intNumberB)
'Compare the values
If intNumberA > intNumberB Then
lblmessage.Text = "Value A is greatest!"
Else
If intNumberA < intNumberB Then
lblmessage.Text = "Value B is greatest!"
Else
If intNumberA = intNumberB Then
lblmessage.Text = "Both values are equal!"
End If
End If
End If
End If


It's providing a real bitch to figure out how to avoid having the program break when letters are entered in the boxes.
>>
File: 1466181166769.jpg (223KB, 722x830px) Image search: [Google]
1466181166769.jpg
223KB, 722x830px
>>55744133
>>
>>55744411
Put this line inside a conditional
Integer.TryParse(TextBoxB.Text, intNumberB)


Like this:
If (Integer.TryParse(TextBoxA.Text, intNumberA) And Integer.TryParse(TextBoxB.Text, intNumberB)) Then


Otherwise If your second number is not a proper number it's not gonna work properly, because you're not checking for that.
>>
>>55744459
Thanks.
>>55744446
I'm sure people mind at this time midnight when /g/ is dead. Deleting in five minutes though. Thanks, I'm going to start lurking this board.
>>
>>55744446
This doesn't fall under tech support, just so you know.
Homework?
You only know it's my homework as I told you it is, many people do this on their own personal time. I'm trying to pick up a skill, this is week 1, cut me some slack.
Thread posts: 9
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.