'While Loop' and multiples of a variable - vb.net

This is another school project, and I'm stumped, so PLEASE help.
I'm supposed to write a program that outputs the numbers 1 to 100, however there are 4 variables. When you enter a value for Variable 1 it takes the numbers that multiples of that number and changes it to the Variable Word that you type in.
The specific question I have is how do I get my variables to be multiples of that value?
This is all I have...thank you for your help.
Public Class Form1
Private Sub lblDiscription_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblDiscription.Click
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub bntCounter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bntCounter.Click
Dim intCounter As Integer = 0
Dim intLeftMultiple As Integer = 1
Dim intRightMultiple As Integer = 1
Dim strLeftWord As String
Dim strRightWord As String
While intCounter < 101
lstDisplay.Items.Add(CStr(intCounter))
intCounter += 1
End If
End While
End Sub
Private Sub lblMiddle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblMiddle.Click
End Sub
End Class
This is what my GUI Looks like.

Related

Use a textbox to store a numeric counter in VB.Net

I want to count with a TextBox.
Here is my code:
Public Class Form1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
OrainsProgressBar1.Increment(1)
If OrainsProgressBar1.Value = 100 Then
Timer3.Start()
Timer1.Stop()
End If
End Sub
Private Sub OrainsTheme1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OrainsTheme1.Click
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Timer1.Start()
Timer2.Start()
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
OrainsProgressBar1.Increment(-1)
If OrainsProgressBar1.Value = 0 Then
Timer1.Start()
Timer3.Stop()
End If
End Sub
Private Sub OrainsButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OrainsButton1.Click
OrainsTextBox1.Text += 100
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
OrainsTextBox1.Text += 1
End Sub
End Class
But I have an error with OrainsTextBox1.Text += 1. VB says:
'Conversion from string "" to type 'Double' is not valid.'
What is the problem?
In the .Net world, the data types of things matter a lot. Strings (like the .Text property) are NOT numbers. You need to convert. Even if someone only enters the digits 0-9 into the textbox, that's still a string of numeric characters, rather than a number. And what should happen if someone enters random text into that textbox that won't convert to a number type at all?
For this code, I suggest building a property, like this:
Private _orainsValue As Double
Public Property OrainsValue As Double
Get
Return _orainsValues
End Get
Set
_orainsValue = Value
OrainsTextBox1.Text = _orainsValue.ToString()
End Set
End Property
That will let you write code like this and have the expected result shown to the user:
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
OrainsVale += 1
End Sub
Note that it does mean you will want to mark the TextBox disabled,though, because this doesn't account for user data entry.
Instead of doing like this OrainsTextBox1.Text += 1
do like this OrainsTextBox1.Text = Val(OrainsTextBox1.Text) + 1
Because .Text is string. Which will append the 1s as "11111111"

Assign a value?

I have this
Public Shared Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
Dim c As Client
Dim Armor As Item = c.Inventory.GetItemInSlot(SlotNumber.Armor)
End Sub
And when I click the button, is crashes and "System.NullReferenceException" pops up , I've searched around and found out that it happens because c is used before it is assigned a value so I'd like to know, what would be the proper way to assign it a value?
try this:
instead of:
Public Shared Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
Dim c As New Client
Dim Armor As Item = c.Inventory.GetItemInSlot(SlotNumber.Armor)
End Sub
try:
Public Shared Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
Dim c As New Client.Inventory
Dim Armor As Item = c.Inventory.GetItemInSlot(SlotNumber.Armor)
End Sub

How to add items from a MenuStrip event to a ListBox using a For Next Loop

That might have sounded weird so let me explain.
I have a school assignment that has me pulling my hair out. I have to get a collection of 5 facts and have them display to a ListBox using a For Next Loop. The user would use an InputBox to input the facts.
I dont know what to put in the For Next to fetch the string from the InputBox. I'm at my wits end and am falling behind.
Here is what I have so far
Public Class frmWWIIFacts
Private Property RemoveAt As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub AddFactToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddFactToolStripMenuItem.Click
Dim intFact As Integer
Dim strInputFact As String
strInputFact = InputBox("Do you want to add a fact?", "Add a fact")
For
Next
strInputFact = InputBox("Do you want to add a fact?", "Add a fact")
End Sub
Private Sub CloseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click
Application.Exit()
End Sub
Private Sub ClearListToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearListToolStripMenuItem.Click
lstFacts.Items.Clear()
End Sub
Private Sub RemoveFactToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RemoveFactToolStripMenuItem.Click
End Sub
I've submitted a reddit post requesting some assistance but its gotten me nowhere. https://www.reddit.com/r/learnprogramming/comments/3t614u/vb2015_using_menustrip_to_addremove_items_in_a/
I would love some help on this. Please ask questions if your confused on my method or if you need to know more.
Sounds like you're trying to do this:
Private Sub AddFactToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddFactToolStripMenuItem.Click
Dim intFact As Integer
Dim strInputFact As String
lstFacts.Items.Clear()
For intFact = 1 To 5
strInputFact = InputBox("Please enter a fact:", "Add a fact")
If Not strInputFact = "" Then
lstFacts.Items.Add(strInputFact)
End If
Next
End Sub

Call function on button click event

How do I call this vb.net function on the button click event?
Private Sub GridView_UDGReport_DataBound1(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBound
For rowIndex As Integer = GridView_UDGReport.Rows.Count - 2 To 0 Step -1
Dim gviewRow As GridViewRow = GridView_UDGReport.Rows(rowIndex)
Dim gviewPreviousRow As GridViewRow = GridView_UDGReport.Rows(rowIndex + 1)
For cellCount As Integer = 0 To gviewRow.Cells.Count - 1
If gviewRow.Cells(cellCount).Text = gviewPreviousRow.Cells(cellCount).Text Then
If gviewPreviousRow.Cells(cellCount).RowSpan < 2 Then
gviewRow.Cells(cellCount).RowSpan = 2
Else
gviewRow.Cells(cellCount).RowSpan = gviewPreviousRow.Cells(cellCount).RowSpan + 1
End If
gviewPreviousRow.Cells(cellCount).Visible = False
End If
Next
Next
End Sub
Since you are not using the parameters anyways, you can simply call the method with Nothing as parameter.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
GridView_UDGReport_DataBound1(Nothing, Nothing)
End Sub
Append the first line so that the sub handles more than one event, as follows:
Private Sub GridView_UDGReport_DataBound1(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBound, Button1.Click
Alternatively, if you need your Click event to run some other code in addition to calling this sub, do this:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'do something
GridView_UDGReport_DataBound1(sender, e)
'do something else
End Sub

IF statement not working as I expected

Hi so im playing with microsoft visual studio 2010 edition and I need to make an if statement work on it.
What im doing is putting a number into a textbox, it then goes into my listbox (however many times I put numbers in like 3-4 numbers). Then it is meant to add them all up and put it into the label after.
Heres the program so far
Public Class Form1
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim Result As Integer
For Each Item As Integer In ListBox1.Items
Result = Result + Item
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Value As String
Value = TextBox1.Text
ListBox1.Items.Add(Value)
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
Label1.Text = "You have a Balance of " + DialogResult.ToString
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
If (String.a
End Sub
End Class
In Visual Basic .NET (which is what your code looks to be in), If statements are formatted like this:
If condition Then
DoSomeCodeHere()
End If
C# code is formatted as
if (condition)
{
DoSomeCodeHere();
}
Do you mean you wan the sum all the amount in the list box and show it in a label after clicking button 2?
If yes add the below should do.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim Result As Integer
For Each Item As Integer In ListBox1.Items
Result = Result + Item
Next
Label1.Text = "You have a Balance of " + Result.ToString
End Sub