Question how to do increments in numbers

Joined
Nov 21, 2012
Messages
7
Programming Experience
Beginner
im pretty much new to programing but i have made this program to output answers and i have that all sorted now i want it so that the answers are displayed in a table format in increments
i have looked online an i havnt been able to find exactly what i want :uncomfortableness:

for example:

the user in puts where i put [[enter text]]

start: [[enter text]]

Increment: [[enter text]]

End [[enter text]]

an i want it to out put the answer in a table format like this:

number 1 Number 2
54 65
55 66
56 67
57 68


thanks for who ever helps me with this :star:


what i have at the moment is:

start= txtbox1 ""
Increment= txtbox2 ""
End= txtbox3 ""
 
Last edited:
Try using a For loop that goes from txtbox1 to txtbox3 and within the loop you can output the desired data. The output might be something like the current loop counter value and the current loop counter value + txtbox2.
 
i have this is, but its not working:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim C As Double

Dim TxtInPut1 As Double
Dim TxtInPut2 As Double
Dim TxtInPut3 As Double

If (radioC.Checked) Then
C = Convert.ToDouble(TxtInPut1)
C = (C * 1.8) + 32 + TxtInPut2

Console.WriteLine(TextBox1)

Do Until TxtInPut3

Loop
TextBox1.Text = Convert.ToString(C)
TextBox1.Text = Convert.ToString(F)
End
End If



End Sub
End Class
 
Hi,

Have a look to see if this is what you are trying to achieve. Add a Button, 3 TextBoxes and a ListBox to a form and replace the code behind the form with the code below. Run the project, enter the Start, End and Increment values and click the button.

VB.NET:
Public Class Form1
 
  Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Dim dblStart, dblIncrement, dblEnd As Double
 
    'this statement checks for valid numeric characters entered into the textboxes
    'and if valid stores the results in the above dblVariables
    If Double.TryParse(txtStart.Text, dblStart) AndAlso Double.TryParse(txtIncrement.Text, dblIncrement) AndAlso Double.TryParse(txtEnd.Text, dblEnd) Then
      'here we loop from the start value to the end value in steps of what is desired
      'we then add the results to a listbox and at the same time calculate the 
      'corresponding fahrenheit
      For dblValue As Double = dblStart To dblEnd Step dblIncrement
        ListBox1.Items.Add(dblValue.ToString & vbTab & ((dblValue * 1.8) + 32).ToString)
      Next
    End If
  End Sub
End Class

If you read through the comments in the code you should be able to pick up what is happening.

Cheers,

Ian
 
im trying to make it so i can put other variables into this, but it keeps having a green line under one of them, here is the code i have:

'This is for Celsius to Fahrenheit
'this statement checks for valid numeric characters entered into the textboxes
'and if valid stores the results in the above dblVariables
If Double.TryParse(TxtStarT.Text, dblStart) AndAlso Double.TryParse(txtIncrement.Text, dblIncrement) AndAlso Double.TryParse(txtEnd.Text, dblEnd) Then
'here we loop from the start value to the end value in steps of what is desired by the user
'we then add the results to a listbox and at the same time calculate the
'corresponding fahrenheit
For dblValuec As Double = dblStart To dblEnd Step dblIncrement
ListBoxOutPut.Items.Add(dblValuec.ToString & vbTab & ((dblValuec * 1.8) + 32).ToString)
Next
ElseIf Double.TryParse(TxtStarT.Text, dblStart) AndAlso Double.TryParse(txtIncrement.Text, dblIncrement) AndAlso Double.TryParse(txtEnd.Text, dblEnd) Then
For dblValueF As Double = dblStart To dblEnd Step dblIncrement
ListBoxOutPut.Items.Add(dblValueF.ToString & vbTab & ((dblValueF * 9 / 5) + 32).ToString)
Next
End If
End Sub
 
Hi,

A couple of points for you here:-

1) A green squiggly line underneath a variable declaration indicates that a variable has not been used within the context it was declared in. I cannot see any unused variable declarations in what you have posted so cannot help you on that one?

2) Your ELSEIF statement for calculating Celsius from Fahrenheit makes no sense whatsoever? The original IF statement only checks for valid numerical values in the TextBoxes. If that conditional statement is false your ElseIf statement will be invoked but its the SAME statement and therefore will never get executed??

What you need to do here is add a GroupBox with Two RadioButtons which you can then check for a either a Celsius or Fahrenheit conversion calculation.

3) When posting code please use the "Go Advance" Button to make your post and then enclose your code in code tags for easy reading.

Hope that helps.

Cheers,

Ian
 
Sorry about that, so this is what i have with the radio buttons (i have a few radio buttons i want) when i use this, it keeps out putting the C degrees but not in degrees F. any advice on how you would do the code?

VB.NET:
Public Class frmTableView

   Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles btnConvert.Click
      Dim dblStart, dblIncrement, dblEnd As Double
      'if no Unit is selected
      If radioC.Checked = False AndAlso radioCm.Checked = False AndAlso radioF.Checked = False AndAlso radioFee.Checked = False AndAlso radioI.Checked = False AndAlso radioKg.Checked = False AndAlso radioKm.Checked = False AndAlso radioMet.Checked = False AndAlso radioMi.Checked = False AndAlso radioP.Checked = False Then
         'show error message
         MessageBox.Show("Please select Conversion!", "Error!")
      Else
         'if user selects Celsius Unit
         If radioC.Checked = True Then
            'This is for Celsius to Fahrenheit
            'this statement checks for valid numeric characters entered into the textboxes
            'and if valid stores the results in the above dblVariables
            If Double.TryParse(TxtStarT.Text, dblStart) AndAlso Double.TryParse(txtIncrement.Text, dblIncrement) AndAlso Double.TryParse(txtEnd.Text, dblEnd) Then
               ListBoxOutPut = ListBoxOutPut
            End If
            'here we loop from the start value to the end value in steps of what is desired by the user
            'we then add the results to a listbox and at the same time calculate the
            'corresponding fahrenheit
            For dblValuec As Double = dblStart To dblEnd Step dblIncrement
               ListBoxOutPut.Items.Add(dblValuec.ToString & vbTab & ((dblValuec * 1.8) + 32).ToString)
            Next

         Else
            If radioF.Checked = True Then
               If Double.TryParse(TxtStarT.Text, dblStart) AndAlso Double.TryParse(txtIncrement.Text, dblIncrement) AndAlso Double.TryParse(txtEnd.Text, dblEnd) Then
                  ListBoxOutPut = ListBoxOutPut
               End If
               For dblValuec As Double = dblStart To dblEnd Step dblIncrement
                  ListBoxOutPut.Items.Add(dblValuec.ToString & vbTab & ((dblValuec * 9 / 5 + 32).ToString))
               Next

            End If
         End If
 
Hi,

A couple more things for you:-

1) The reason why you get the same result for calculating Fahrenheit as you do for Celsius is because your calculation is actually the calculation for Celsius. You currently have:-
(dblValuec * 9 / 5 + 32) which is exactly the same as ((dblValuec * 1.8) + 32).

Your calculation for Fahrenheit should be:-
(((dblValuec - 32) * 5) / 9)

2) You have totally misunderstood how to effectively use the If statement that was provided. You currently have:-

VB.NET:
If Double.TryParse(TxtStarT.Text, dblStart) AndAlso Double.TryParse(txtIncrement.Text, dblIncrement) AndAlso Double.TryParse(txtEnd.Text, dblEnd) Then
  ListBoxOutPut = ListBoxOutPut
End If
 
For dblValuec As Double = dblStart To dblEnd Step dblIncrement
  ListBoxOutPut.Items.Add(dblValuec.ToString & vbTab & ((dblValuec * 1.8) + 32).ToString)
Next

ListBoxOutPut = ListBoxOutPut does not mean anything and this is where your For loop should be. As it is now the For loop will still execute if invalid entries are made in the TextBoxes and the project will crash. This should be:-

VB.NET:
If Double.TryParse(TxtStarT.Text, dblStart) AndAlso Double.TryParse(txtIncrement.Text, dblIncrement) AndAlso Double.TryParse(txtEnd.Text, dblEnd) Then
  For dblValuec As Double = dblStart To dblEnd Step dblIncrement
    ListBoxOutPut.Items.Add(dblValuec.ToString & vbTab & ((dblValuec * 1.8) + 32).ToString)
  Next
End If

Hope that helps.

Cheers,

Ian
 
Back
Top