Solved

VBasic update

Posted on 2000-05-02
3
173 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

762 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

10 Experts available now in Live!

Get 1:1 Help Now