Solved

VBasic update

Posted on 2000-05-02
3
174 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
  • 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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now