Solved

VBasic update

Posted on 2000-05-02
3
178 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

691 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