Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 如何将此代码从vb6转换为delphi_Vba_Delphi 7 - Fatal编程技术网

Vba 如何将此代码从vb6转换为delphi

Vba 如何将此代码从vb6转换为delphi,vba,delphi-7,Vba,Delphi 7,端接头 请帮助我,因为我不能使用vb,也不能转换它,因为我还是新手它看起来像这样: Private Sub acak ( ) Dim random As New Random ( ) Dim a, c, m, i, y As Byte Dim x( ) As Byte = {0,1,2,3,4,5,6,7,8,9,10} a = 5 c = 7 m = 8 x (0) = random.Next (1, 16) For i = 1 To 16 x(i) = (a*x(i-1)+c)

端接头


请帮助我,因为我不能使用vb,也不能转换它,因为我还是新手

它看起来像这样:

Private Sub acak ( )
Dim random As New Random ( )
Dim a, c, m, i, y As Byte
Dim x( ) As Byte = {0,1,2,3,4,5,6,7,8,9,10}
a = 5
c = 7
m = 8
x (0) = random.Next (1, 16)
For i = 1 To 16
       x(i) = (a*x(i-1)+c) Mod m
       If x(i) = 0 Then
           y = i
       End if
 Next
 Button1.Text = x(16)
 acakbutton ()

此代码的目的是什么?它声明了一个11字节的数组,但用17个值填充,并且声明了
y
,甚至分配了值,但实际上没有用于任何事情。而且
Random
不是VB6类,它是.NET类,所以这是VB.NET代码。@RemyLebeau啊,对不起,这是我的错。不是“16”而是“8”。这段代码来自我大学图书馆的书。这是关于线性同余发生器的方法。我想了解一下。或者你可以给我一些建议吗?我投票结束这个问题,因为堆栈溢出不是代码翻译service@DavidHeffernan好的,很抱歉,我将结束这个问题。谢谢你的建议
interface

uses
 ...;

type
  TMyForm = class(TForm)
    Button1: TButton;
    ... 
  private
    procedure acak;
   ... 
  end;

...

implementation

uses
  Math;

procedure TMyForm.acak;
var
  a, c, m, i, y: Byte;
  x: array[0..16] of Byte;
begin
  Randomize;
  for i := 0 to 10 do
    x[i] := i;
  a := 5;
  c := 7;
  m := 8;
  x[0] := RandomRange(1, 16);
  for i := 1 to 16 do
  begin
    x[i] := (a*x[i-1]+c) mod m;
    if x[i] = 0 then
      y := i;
  end;
  Button1.Text := IntToStr(x[16]);
  acakbutton;
end;