Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
Public Class Form1
    Function Data()
        Dim speed As Single
        Dim distance, time, average_speed As Integer

        txttime1.Text = CInt(time)
        txttime2.Text = CInt(time)
        txttime3.Text = CInt(time)
        txttime4.Text = CInt(time)

        speed = distance / time

        Dim valid_chars As String
        valid_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

        Dim valid_int As Integer = "1234567890"

        average_speed = 31.3

        Dim foreign As String
        foreign = Rnd(valid_chars & valid_int & valid_chars & valid_int)

        Dim uk_plate As String
        uk_plate = Rnd(valid_chars & valid_chars & valid_int & valid_int & valid_chars & valid_chars & valid_chars)



This is my code, I need help with a solution.
My aim is to create a car plate and I need help creating a car plate w/ the UK car plate format (2 letters, 2 numbers and 3 letters in that order)
Posted
Updated 5-Jan-16 0:07am
v2
Comments
John C Rayan 5-Jan-16 6:03am    
More details would help.

Take a look at this code:
VB
' You have declared a variable time, the value in VB is initialized with 0
Dim distance, time, average_speed As Integer

' ...

' ... you try to divide through null
speed = distance / time
 
Share this answer
 
It doesn't work because it doesn't do anything.
All it does is add the string "ABCDEFGHIJKLMNOPQRSTUVWXYZ" to itself 5 times, include the interes twice and pass that:
"ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567890ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
to the Rnd fucntion. Which almost certainly doesn't know what to do with it...

Throw that away.
Move your valid_chars and valid_int to class level Shared strings.
Create a class level Random instance, and GetLetter and GetDigit methods which use it to generate an index into the appropriate Shared string and return a single character.
Then call them the appropriate number of times.

But...be aware that that won't necessarily generate a valid UK number plate: AA99AAA will not be valid for a lot of years, and AA16III or AA16OOO will never be valid...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900