Hi
Thank you very much for your offer of assistance.
The program I have been told to write requires a user to input any number in the textbox, should the user then click on the factors button, the factors of the said number should be displayed in a listbox.
So far, I have tried using a For/Next loop following my guidance notes. However I am receiving an error.
My code looks like this:
Private Sub btnFactors_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFactors.Click 'Calculate the factors of the number entered by the user
Dim intCount As Integer Dim intNumber As Integer Dim intSum As Integer Dim intArrayFactors As Integer intNumber = CInt(txtNumber.Text) Dim intFactors As Integer Dim intPrimeFactors As Integer intFactors = lstFactors.SelectedIndex intPrimeFactors = lstPrimeFactors.SelectedIndex
If txtNumber.Text = "" Then 'Nothing was entered in the user input textbox MessageBox.Show("Input in text box required", "Input a number", _ MessageBoxButtons.OK, MessageBoxIcon.Exclamation) End If
For intCount = 1 To Int(Math.Sqrt(intNumber)) If intNumber Mod intCount = 0 Then intSum += 1 intArrayFactors(intSum) = intNumber / intCount
End If Next
End Sub
I have spent absolute hours on this, reading the textbook, etc and am still stuck - any help would be greatly appreciated.
Many thanks, look forward to hearing from you. |