为什么这段代码不起作用? [英] Why doesn't this code work?

查看:69
本文介绍了为什么这段代码不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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)







这是我的代码,我需要一个解决方案的帮助。

我的目标是创建一个车牌,我需要帮助创建一个带有英国车牌格式的车牌(2个字母,2个数字和3个字母的顺序)




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)

推荐答案

看一下这段代码:

Take a look at this code:
' 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


它不起作用,因为它没有做任何事情。

它所做的只是将字符串ABCDEFGHIJKLMNOPQRSTUVWXYZ添加到自身5次,包括两次interes和通过:

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"

到Rnd fucntion。几乎肯定不知道该怎么做...



扔掉它。

将你的valid_chars和valid_int移到课堂上level共享字符串。

创建一个类级别随机实例,以及GetLetter和GetDigit方法,它们使用它来生成相应共享字符串的索引并返回单个字符。

然后给他们打电话适当的次数。



但是......请注意,这不一定会产生有效的英国号牌:AA99AAA将无效很多年了,AA16III或AA16OOO永远不会有效...

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...


这篇关于为什么这段代码不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆