Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual Basic v6.0 use of option buttons (Help Please) 1

Status
Not open for further replies.

Phalken

Programmer
Jan 8, 2004
24
US
I am a self-taught programmer and I am stuck. I need to understand how to use option buttons to manipulate the data from it's corresponding textbox. I really need to breach this barrier I am having with option buttons, it will really make my applications much more felxible and user friendly.

Application Description: This application calculates an unknown encoding video bitrate. The unknown encoding video bitrate is determined based upon the specifications the user inputs into the calculator.

My form has 4 textboxes. 1 of the textboxes the user does not interface with because the "Unknown Encoded Video Bitrate" is calculated into that textbox for the user to see, so he/she knows at what bitrate to encode the video.

The other three text boxes are as follows: 1.) Encoding Audio Bitrate, 2.) Video Length Time . . . (3 option buttons included to this textbox for seconds, minutes, and hours), 3.) Encoded Video Size . . . (3 option buttons included to this textbox for Kb, Mb, and Gb).

Then their is the cmdCalculate_Click() event button to calculate the user's inputed data.

I need to understand and learn how to code my cmdCalculate_Click() event with the textbox option buttons.

Here is my current working code: (Note that this code obviously has no option buttons attached to it. The "Video Length Time" textbox MUST be inputted as Seconds, and the "Encoded Video Size" textbox MUST be inputted as Kb.)

I need to learn how to declare my option buttons and code them into my cmdCalculate_Click() event.

Private Sub cmdCalculate_Click()

txtEVB.Text = Format((Val(txtEVS.Text) - txtEAB.Text * (2048 / 2018) * (Val(txtVLT.Text) / 8)) / ((2048 / 2018) * (Val(txtVLT.Text) / 8)), "###,##0.0")

End Sub

Thanks you in advance for all help. I really need to get this down!

-- Matthew
 
I forgot to post the conversions:


Video Length Time textbox option buttons:

Seconds: optVLT_s if yes, txtVLT.Text/8
Minutes: optVLT_m if yes, txtVLT.Text/(8/60)
Hours: optVLT_h if yes, txtVLT.Text/(8/3600)

Encoded Video Size textbox option buttons:

Kb: optEVS_Kb if yes, txtEVS.Text * 1
Mb: optEVS_Mb if yes, txt.EVS.Text * 1000
Gb: optEVS_Gb if yes, txt.EVS.Text * 10000

Thanks again everyone.
-- Matthew
 
You test option buttons by their .value. In your case, you would have to use a frame around the textboxes with option buttons and their appropriate option buttons so that the system knows that those option buttons work together, and the option buttons for the other textbox work together. By work together, I mean that only one of each group of three can be selected rather than one of the six. Also, you will want to set the value of your default option button to true so that it shows correctly at run time.

To code it, you would be looking at something like the following:

Code:
if optvlt_s.value = true then
   sngVLT = txtVLT.Text/8
end if
if optvlt_m.value = true then
   sngVLT = txtVLT.Text/(8/60)
end if
if optvlt_h.value = true then
   sngVLT = txtVLT.Text/(8/3600)
end if

I'm suggesting puttin the value into a variable and then use the variable for your formula so that the user doesn't have to see the conversion occur in the textboxes.

Hope that helps!
 
Thank you very much for your helpful description to solve my problem.

I have come up with this so far (I just need to adjust my code part - I am getting a syntax error) but so far eveything else is solid.

Private Sub cmdCalculate_Click()

Dim Seconds As String
Dim Minutes As String
Dim Hours As String
Dim Kb As String
Dim Mb As String
Dim Gb As String

If optVLT_s.Value = True Then
Seconds = (txtSeconds.Text) / (8)
End If

If optVLT_m.Value = True Then
Minutes = (txtMinutes.Text) / (8 / 60)
End If

If optVLT_h.Value = True Then
Hours = (txtHours.Text) / (8 / 3600)
End If

If optEVS_Kb.Value = True Then
Kb = (txtKb.Text) / (1)
End If

If optEVS_Mb.Value = True Then
Mb = (txtMB.Text) * (1000)
End If

If optEVS_Gb.Value = True Then
Gb = (txtGb.Text) * (10000)
End If

txtEVB.Text = Format((Val(var1) - var2 * (2048 / 2018) * (Val(var3)) / 8)) / ((2048 / 2018) * (Val(var4) / 8)), "###,##0.0")

End Sub

-- Matthew
 
actually my calculation is still messed up, but here is something more closer:

txtEVB.Text = Format((Val(txtKb.Text) - txtEAB.Text * (2048 / 2018) * (Val(txtSeconds.Text / 8)) / ((2048/2018) * (Val(txtSeconds.Text) / 8)), "###,##0.0")

-- Matthew

still bugs, grrrrr (a learning process ;)
 
You'll have to work out the formula, but you should be looking at something like this:
Dim sngEVS As Single
Dim sngVLT As Single

If optvlt_s.Value = True Then
sngVLT = (txtvlt.Text) / (8)
End If

If optvlt_m.Value = True Then
sngVLT = (txtvlt.Text) / (8 / 60)
End If

If optvlt_h.Value = True Then
sngVLT = (txtvlt.Text) / (8 / 3600)
End If

If optevs_kb.Value = True Then
sngEVS = (txtevs.Text) / (1)
End If

If optevs_mb.Value = True Then
sngEVS = (txtevs.Text) * (1000)
End If

If optevs_gb.Value = True Then
sngEVS = (txtevs.Text) * (10000)
End If

txtevb.Text = Format(sngEVS - (txteab.Text * (2048 / 2018) * (sngVLT / 8)) / ((2048 / 2018) * (sngVLT / 8)), "###,##0.0")

This site is not normally intended for giving out the answers(rather to point you in the right direction), but it looks like you could use some help working out the logic of option boxes and referring to the right fields and variables. Take a look at the above and let me know if this is doing what you are after.

Hope that helps!
 
Thanks for the help in understanding the logic of option buttons. Giant help . . . thanks.

-- Matthew
 
Thanks again for your help with understanding the concept of option button logix. I have it nailed down and your help was solid. Thanks so much.

Here is the code to my fully working application! Thanks to your help my current and future applications will be much more flexible!

'**************************************************************************************
'
' Project: Encoding Video Bitrate Calculator
' File: frmEVBCalculator_CBR.vbp
' Compiled Version: v1.00
' Compilation Date: N/A
' Compiler: N/A
'
'
' Programmer: Phalken
'
' Purpose: This application calculates an unknown encoding video bitrate.
' The unknown encoding video bitrate is determined based upon the
' specifications the user inputs into the calculator.
'
'**************************************************************************************

Private Sub cmdCalculate_Click()

Dim sngEVS As Single
Dim sngVLT As Single

If optVLT_s.Value = True Then
sngVLT = (txtVLT.Text) / (8)
End If

If optVLT_m.Value = True Then
sngVLT = (txtVLT.Text) / (2 / 15)
End If

If optVLT_h.Value = True Then
sngVLT = (txtVLT.Text) / (1 / 450)
End If

If optEVS_Kb.Value = True Then
sngEVS = (txtEVS.Text) / (1)
End If

If optEVS_Mb.Value = True Then
sngEVS = (txtEVS.Text) * (1024)
End If

If optEVS_Gb.Value = True Then
sngEVS = (txtEVS.Text) * (1048576)
End If

txtEVB.Text = Format((txtEAB.Text * (2048 / 2018) * (sngVLT) - sngEVS) / -((2048 / 2018) * (sngVLT)), "###,##0.0")

End Sub
Private Sub cmdExit_Click()
' Unloads the form from system memory and terminates the application.
Unload frmEVBCalculator_CBR
End
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top