Skip to content
View in the app

A better way to browse. Learn more.

Tip.It Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

VB help needed

Featured Replies

Hey there, i am currently working on a Visual Basic 6.0 project for school, and i have run into a little problem here that i need assistance on.

 

 

 

 

 

 

 

I won't go into details on the assignment, because its irrelivent, i'm simply having a problem with my error handling on it. I need to provide a message box popup that will display if none of the 3 options buttons in a frame are selected.

 

 

 

 

 

 

 

I was thinking about how i was going to do this for quite some time, and the best idea i could come up with was to do this...

 

 

 

 

 

 

 

Dim int1, int2, int3, intTotal As Integer







If optOverNight.Value = False Then



 int1 = 1



ElseIf optDays.Value = False Then



 int2 = 2



ElseIf optWeeks.Value = False Then



 int3 = 3



End If







intTotal = int1 + int2 + int3







If intTotal = 6 Then



 MsgBox "You must select a delivery option, vbOkOnly, "Error"



End If



 

 

 

 

 

 

 

But this code obviously did not work, so i was wondering if anybody had another idea i could try. I feel like i am making this harder than it actually is, so someone hitting me with some common sense would be much appreciated.

Hey there, i am currently working on a Visual Basic 6.0 project for school, and i have run into a little problem here that i need assistance on.

 

 

 

 

 

 

 

I won't go into details on the assignment, because its irrelivent, i'm simply having a problem with my error handling on it. I need to provide a message box popup that will display if none of the 3 options buttons in a frame are selected.

 

 

 

 

 

 

 

I was thinking about how i was going to do this for quite some time, and the best idea i could come up with was to do this...

 

 

 

 

 

 

 

Dim int1, int2, int3, intTotal As Integer







If optOverNight.Value = False Then



 int1 = 1



ElseIf optDays.Value = False Then



 int2 = 2



ElseIf optWeeks.Value = False Then



 int3 = 3



End If







intTotal = int1 + int2 + int3







If intTotal = 6 Then



 MsgBox "You must select a delivery option, vbOkOnly, "Error"



End If



 

 

 

 

 

 

 

But this code obviously did not work, so i was wondering if anybody had another idea i could try. I feel like i am making this harder than it actually is, so someone hitting me with some common sense would be much appreciated.

 

 

 

 

 

 

 




Dim selectSomething



selectSomething = (optOverNight.Value Or optDays.Value Or optWeeks.Value)







If Not selectSomething Then



 MsgBox "Please select a delivery option first", vbOkOnly, "Error"



End If



 

 

 

 

 

 

 

Should work. Using Or makes sure that if any of them is true, the selectSomething value is true too. I may be off a bit with braces and such, it's been some time since I wrote VB :).

  • Author

Thank you very much, that did the trick. It works great, it's just that when i use the command button to activate the code, the message box pops up, but the code continues to run. Nothing a little

Exit Sub

couldn't fix.

  • Author

I'm curious though, how where you able to declare the "selectSomething" Variable without giving it a "type". What i mean is using

Dim selectSomething As Integer

for example?

 

 

 

 

 

 

 

We have not used this sort of code in our class yet, so i was just wondering, incase the teacher wants me to go into detail on what code i used and how it works(she tends to do that).

Ah right. Declaring a variable without a type gives you a variable of type Variant, which can basically become anything. I forgot the typedeclaration, to be honest, because I'm more used to write stuff in JavaScript or php now, both of which either don't have or hardly ever use typed declarations.

 

 

 

 

 

 

 

In this case, you could also use:

 

 

 

Dim selectedSomething As Boolean

 

 

 

A boolean datatype can only be true or false, in case you didn't use that stuff yet.

 

 

 

 

 

 

 

I should also note that your own example didn't work because you used:

 

 

 

If

 

 

 

ElseIf

 

 

 

ElseIf

 

 

 

End If

 

 

 

 

 

 

 

It would have worked if you used

 

 

 

If

 

 

 

End If

 

 

 

If

 

 

 

End If

 

 

 

If

 

 

 

End If

 

 

 

 

 

 

 

This is because elseif blocks only get executed if the if-condition fails. So in your own code, the code after the first elseif only got executed if the first option was true, and the code after the second one only if both the first option and the second were true. Which is impossible.

 

 

 

Moral of the story: don't use elseif just because you have another if just before it which is very similar ;).

 

 

 

 

 

 

 

Using Booleans is neater in this case, as you may have noticed.

 

 

 

 

 

 

 

Something else you should note is that if you give your variables decent names, code makes more sense and becomes easier to read if you do:

 

 

 

If Not somethingWasSelected Then ...

 

 

 

Instead of:

 

 

 

If somethingWasSelected = False Then ...

 

 

 

 

 

 

 

Both give the same result when handling the boolean datatype. Using the Not operator (it's an operator) on an integer may give funny results. I wouldn't know exactly what would happen (maybe the code wouldn't even run, can't recall that).

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.