PDA

View Full Version : Could use some vb help on a school assignment



Erous
11-25-2016, 09:36 PM
Because I'm just that bad at programming, I'm trying to complete the following in VB using Visual Studio. Any help would be appreciated. My last programming class ever and just really trying to get through it.

1. Write a program to display 1000 8-character random user IDs in a text box after you click a button. Make sure the program verifies that none of the IDs are identical. Each userid should include a mixture of alphabetic characters and numbers.

2. Write a function that will calculate the area of a sphere and will handle all types of possible errors

Figure the 1st one should be easy enough, I've been researching and working through code trying to get it to work out.

Whirlin
11-25-2016, 10:50 PM
Only familiar with MS Office VBA... but concepts similar enough:
1)
Loop 8 times
Random 0,1
if 0, generate a random number
if 1, generate a random letter
If loop run = 0, set value as above
If loop run >0, set value = value + new value
close loop
if most recent value matches any previous value, return to previous loop
if most recent value does not match any previous value, add 1 to counter, and repeat


second one:
How many variables are there really? just pi * 4 r^2
So... is r positive, not 0.
If number(r) = false then return = "Please enter a number"
If r < 0 then return = "Please use a positive radius"
If r = 0 then return = "No physical area"
Return = pi * 4 * r^2

something like that should work... syntax is all you.

Erous
11-25-2016, 11:13 PM
Thanks Whirlin, I think I figured it out for anyone interested:


Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub
Public Function makeID() As Object
Dim r, a, q, c, b As Object
r = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
a = Len(r)
q = 8
Randomize()
c = ""
For intstep = 1 To q
b = Int((a * Rnd()) + 1)
c = c & Mid(r, b, 1)
Next
makeID = c
End Function

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim a As String
While ListBox1.Items.Count < 1001
a = makeID()
ListBox1.Items.Add(a)
End While

End Sub
End Class

TamiTamiSchall
08-05-2020, 07:37 AM
Because I'm just that bad at programming, I'm trying to complete the following in VB using Visual Studio. Any help would be appreciated. My last programming class ever and just really trying to get through it.

1. Write a program to display 1000 8-character random user IDs in a text box after you click a button. Make sure the program verifies that none of the IDs are identical. Each userid should include a mixture of alphabetic characters and numbers.

2. Write a function that will calculate the area of a sphere and will handle all types of possible errors

Figure the 1st one should be easy enough, I've been researching and working through code trying to get it to work out.

I also had a visual basic course at university. This course was very interesting, so I could concentrate on only one subject and could not do other subjects, especially those that I did not love like writing papers. That's why I bought papers from the service https://cheetahpapers.com/essay/do/ and focused my attention on only one subject - the visual basic course.