Question Help with setting default combobox String

gho5t

Member
Joined
Aug 26, 2013
Messages
13
Programming Experience
1-3
Hello brothers.

I am coming to you today with a new and most probably easy fixed issue.

I have a series of calculations that are completed upon clicking "button3"
My program will error because some of the calculations require a number to be entered in some of the textboxes for example "Height" and "Width"

But i need to be able to set a default string in the combobox and have no idea how.

Here is my code:

VB.NET:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        ' SD2 6mm Calcs
        sd26mmhead.Text = widthtxt.Text * 14.55 / 1000 * qty1.Text
        sd26mmsill.Text = widthtxt.Text * 12.97 / 1000 * qty1.Text
        sd26mmguides.Text = heighttxt.Text * 60.45 / 1000 * qty1.Text
        sd26mmlapseal.Text = widthtxt.Text * 19.0 / 1000 * qty1.Text
        sd26mmhardware.Text = widthtxt.Text * 35.15 / 1000 * qty1.Text
        sd26mmmanu.Text = widthtxt.Text * 228.0 / 1000 * qty1.Text
        sd26mminstall.Text = widthtxt.Text * 228.0 / 1000 * qty1.Text
        sd26mmglass.Text = heighttxt.Text * widthtxt.Text / 1000000 * mememe.Text * qty1.Text


        ' String to load the 6mm calcs
        Me.sd26mmtxt.Text = sd26mmhead.Text * 1 + sd26mmsill.Text * 1 + sd26mmguides.Text * 1 + sd26mmlapseal.Text * 1 + sd26mmhardware.Text * 1 + sd26mmmanu.Text * 1 + sd26mminstall.Text * 1 + sd26mmglass.Text * 1

Thank-you in advanced.
 
Um, what ComboBox? Try providing a FULL and CLEAR explanation of the whole problem.

Also, I can only assume that all those multiplications by 1 are to convert Strings to Integers. Instead of that dodgy hack, how about you do it properly? If you want to convert a String to an Integer then you can use CInt. You can also use CDbl to convert to Double, etc. Better still, given that you're using TextBoxes for input and the user could theoretically enter anything, use Integer.TryParse or Double.TryParse or the like to validate and convert in one go. That will prevent your app from crashing on invalid input, which it will currently do.

Mind you, that last calculation shouldn't need any conversion at all. You perform a bunch of calculations and display the results in controls of some sort, then get the values back from those controls to do the final calculation. BAD! Put the numbers in numeric variables and use those variables for the calculation. You can then display everything as required but never have to get anything back from those controls.
 
please ignore my first question.

How do i set a default selection in a combo box, example my combobox selections are:

Selection0
Selection1
Selection2

How do i set the combobox to have the combobox selection0 to be the default value.

Here is my code relevant to this question.

VB.NET:
Select Case Me.glss.SelectedIndex

            Case 0
                mememe.Text = 95 'Clear Lam 6mm
            Case 1
                mememe.Text = 190 'Clear Lam 10mm
            Case 2
                mememe.Text = 0 'Clear Lam IGU (N/A)
            Case 3
                mememe.Text = 95 'Clear Tuff 6mm
            Case 4
                mememe.Text = 190 'Clear Tuff 10mm
            Case 5
                mememe.Text = 190 'Clear Tuff IgU
            Case 6
                mememe.Text = 171 'Comfort Plus 6mm
            Case 7
                mememe.Text = 275 'Comfort Plus 10mm
            Case 8
                mememe.Text = 0 'Comfort Plus IGU (N/A)
            Case 9
                mememe.Text = 171 'Etech Tuff 6mm
            Case 10
                mememe.Text = 275 'Etech Tuff 10mm
            Case 11
                mememe.Text = 266 'Etech Tuff IGU
            Case 12
                mememe.Text = 171 'Evantage Tuff 6mm
            Case 13
                mememe.Text = 275 'Evantage Tuff 10mm
            Case 14
                mememe.Text = 266 'Evantage Tuff IGU
            Case 15
                mememe.Text = 171 'Matalux Tuff 6mm
            Case 16
                mememe.Text = 275 'Matalux Tuff 10mm
            Case 17
                mememe.Text = 266 'Matalux Tuff IGU
            Case 18
                mememe.Text = 171 'Soltech Tuff 6mm
            Case 19
                mememe.Text = 275 'Soltech Tuff 10mm
            Case 20
                mememe.Text = 266 'Soltech Tuff IGu
            Case 21
                mememe.Text = 152 'Trans Lam 6mm
            Case 22
                mememe.Text = 228 'Trans Lam 10mm
            Case 23
                mememe.Text = 0 'Trans Lam IGU (N/A)
            Case 24
                mememe.Text = 0 'Solar Ban 6mm (N/A)
            Case 25
                mememe.Text = 0 'Solar Ban 10mm (N/A)
            Case 26
                mememe.Text = 304 'Solar Ban IGU 4mm
            Case 27
                mememe.Text = 351 'Solar Ban IGU 6mm


        End Select
 
also,

I tried declaring the textboxes as double instead of using them as .text

Now when I try to perform the calculation nothing works it just shows the output textbox being (sd26mm) as 0

VB.NET:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Dim sd26mmhead As Double
        Dim sd26mmsill As Double
        Dim sd26mmguides As Double
        Dim sd26mmlapseal As Double
        Dim sd26mmhardware As Double
        Dim sd26mmmanu As Double
        Dim sd26mminstall As Double
        Dim sd26mmglass As Double
        Dim widthtxt As Double
        Dim heighttxt As Double
        Dim qty1 As Double
        Dim mememe As Double
        Dim sd26mmtxt As Double


        ' SD2 6mm Calcs
        sd26mmhead = widthtxt * 14.55 / 1000 * qty1
        sd26mmsill = widthtxt * 12.97 / 1000 * qty1
        sd26mmguides = heighttxt * 60.45 / 1000 * qty1
        sd26mmlapseal = widthtxt * 19.0 / 1000 * qty1
        sd26mmhardware = widthtxt * 35.15 / 1000 * qty1
        sd26mmmanu = widthtxt * 228.0 / 1000 * qty1
        sd26mminstall = widthtxt * 228.0 / 1000 * qty1
        sd26mmglass = heighttxt * widthtxt / 1000000 * mememe * qty1


        ' String to load the 6mm calcs
        sd26mmtxt = sd26mmhead * 1 + sd26mmsill * 1 + sd26mmguides * 1 + sd26mmlapseal * 1 + sd26mmhardware * 1 + sd26mmmanu * 1 + sd26mminstall * 1 + sd26mmglass * 1


    End Sub
 
hmm, i tried the following and did not work.

Select Case Me.glss.SelectedIndex = 0

I'm really not sure what that was supposed to achieve but if you get the SelectedIndex to determine which item is selected then logic suggests that you set the SelectedIndex to select an item.
 
May I ask for 5 minutes of your time on either Skype, ventrillo or TS3?

As I am still unaware of what you are saying.
 
also,

I tried declaring the textboxes as double instead of using them as .text

Now when I try to perform the calculation nothing works it just shows the output textbox being (sd26mm) as 0

VB.NET:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Dim sd26mmhead As Double
        Dim sd26mmsill As Double
        Dim sd26mmguides As Double
        Dim sd26mmlapseal As Double
        Dim sd26mmhardware As Double
        Dim sd26mmmanu As Double
        Dim sd26mminstall As Double
        Dim sd26mmglass As Double
        Dim widthtxt As Double
        Dim heighttxt As Double
        Dim qty1 As Double
        Dim mememe As Double
        Dim sd26mmtxt As Double


        ' SD2 6mm Calcs
        sd26mmhead = widthtxt * 14.55 / 1000 * qty1
        sd26mmsill = widthtxt * 12.97 / 1000 * qty1
        sd26mmguides = heighttxt * 60.45 / 1000 * qty1
        sd26mmlapseal = widthtxt * 19.0 / 1000 * qty1
        sd26mmhardware = widthtxt * 35.15 / 1000 * qty1
        sd26mmmanu = widthtxt * 228.0 / 1000 * qty1
        sd26mminstall = widthtxt * 228.0 / 1000 * qty1
        sd26mmglass = heighttxt * widthtxt / 1000000 * mememe * qty1


        ' String to load the 6mm calcs
        sd26mmtxt = sd26mmhead * 1 + sd26mmsill * 1 + sd26mmguides * 1 + sd26mmlapseal * 1 + sd26mmhardware * 1 + sd26mmmanu * 1 + sd26mminstall * 1 + sd26mmglass * 1


    End Sub

You can't declare a TextBox as a Double. A TextBox is a TextBox. Maybe you mean that you declared some Double variables instead of using TextBoxes.

As for nothing being displayed, of course nothing is displayed because you're not displaying anything. Nor are you actually using any user input. Think about what you have to do before you try to do it.

1. Retrieve the user input, validate it and convert it to numbers.

That means getting the Strings from the appropriate controls, checking that the required data is present and that the data is numeric and then converting it to numbers and storing those values in numeric variables. Don't do anything else until you have that working. Once I see that, I'll help with the next step.
 
Back
Top