Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBasic update

Posted on 2000-05-02
3
Medium Priority
?
181 Views
Last Modified: 2010-05-18
first off i did not want the whole program written for me...this is what i have so far...

i need to know why my option buttons are not working properly?

This is my second form.my optCD=CD selection option button and my optTape=Tape selection

what i need it to do is read from my data file to determine if the choice they have selected from the combo-box comes in a Tape or a CD...If there selection is not available in Tape when they select the Tape option or CD when they select the CD option then i need an appropriate message-box to say that it is not available...If it is available then they are ok...I assigned the Genre variable in my data file to the Tape and CD part.

This is a copy of my data file i have created:(hey do not laugh...our teacher has a strong imagination)
"My baby drives a Fisher Price 4x4",5,39.95,"CD"
"Instant Cornbread Blues",3,47.00,"CD"
"Early to bed,early to rise,early to class,yeah...whatever",12,21.95,"Tape"
"Huntin,Fishin,and 4-wheelin...woohoo!!",7,20.00,"CD"
"Sweatin in da Kitchen",0,115.95,"Tape"
"Robert,O Robert, why didn't we retire?",5,33.50,"Tape"
"Leather and Chains",0,55.10,"CD"
"If it aint gotta heel,then it aint called a shoe",11,125.00,"Tape"
"Doing the twist...Microsoft style",1,5.32,"CD"


Private Sub Check1_Click()
    txtComment.Visible = True
End Sub

Private Sub cmdRum_Click()
    Dim Song As String
    Dim Quantity As Integer
    Dim Price As Integer
    Dim Genre As String
    Dim x As Boolean
   
       
    x = True
   
    Open "a:\music store.txt" For Input As #1
    Do While Song <> Combo1.Text
    Input #1, Song, Quantity, Price, Genre
    Loop
   
   
    If Song <> Combo1.Text Then
       MsgBox ("bet you wish I had it")
       x = False
    End If
   
    If txtQuantity > Quantity Then
       MsgBox "Sold Out"
       x = False
   
        If Option1.Value = True And Genre = "Tape" Then
        MsgBox "Not available as CD"
           
            Else
             If Option2.Value = True And Genre = "CD" Then
             MsgBox "Not available as Tape"
               
                If x = True Then
                Unload Form2
                Form3.Show
                End If
            End If
        End If
    End If
     
         
     Close #1
End Sub


0
Comment
Question by:Jenny30
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Expert Comment

by:pauljk
ID: 2771526
Quick hint for you...

I don't think you should continue going through the code when they first condition is not met.  After an x = False, you might want an exit sub.

0
 
LVL 4

Accepted Solution

by:
Jeremy_D earned 200 total points
ID: 2773831
I've got the feeling that this part:

    If txtQuantity > Quantity Then
       MsgBox "Sold Out"
       x = False
     
        If Option1.Value = True And Genre = "Tape" Then
        MsgBox "Not available as CD"
             
            Else
             If Option2.Value = True And Genre = "CD" Then
             MsgBox "Not available as Tape"
                 
                If x = True Then
                Unload Form2
                Form3.Show
                End If
            End If
        End If
    End If
     
         
should be something like this:

    If txtQuantity > Quantity Then
       MsgBox "Sold Out"
       x = False
    ElseIf Option1.Value = True And Genre = "Tape" Then
        MsgBox "Not available as CD"
    ElseIf Option2.Value = True And Genre = "CD" Then
        MsgBox "Not available as Tape"
    End If
    If x = True Then
        Unload Form2
        Form3.Show
        End If
    End If
     
         
     
0
 
LVL 4

Expert Comment

by:Jeremy_D
ID: 2776599
A few little tips (to impress your teacher):

In stead of writing:

If x = True Then ...

You can use:

If x Then ...

( 'x = True' evaluates to True if x contains the value True, but you can also use the value itself as the test rather then an expression. x evaluates to True whenever it holds the value True)

The same goes for the OptionX.Value expressions, so:

ElseIf Option1.Value = True And Genre = "Tape" Then ...

can be rewritten to:

ElseIf Option1.Value And Genre = "Tape" Then ...
       
Yet another thing you can do to make it look a bit more professional is this:

    Dim strPrompt As String

    If txtQuantity > Quantity Then
       strPrompt = "Sold Out"
       x = False
    ElseIf Option1.Value And Genre = "Tape" Then
        strPrompt = "Not available as CD"
    ElseIf Option2.Value And Genre = "CD" Then
        strPrompt = "Not available as Tape"
    End If
    If strPrompt <> vbNullString Then MsgBox strPrompt
    If x Then
        Unload Form2
        Form3.Show
    End If

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question