VB code overflow problem, novice, please help a look
Time:09-17
Option Base 1 Private Sub Command1_Click ()
Dim arr () As an Integer, m As an Integer, I, As an Integer, a As Integer For a=0 To Op1. Count - 1 If Op1 (a). The Value=https://bbs.csdn.net/topics/ture Then M=Val (Op1) (a). The Caption) End the If Next a ReDim arr (m) Arr (1)=1 Arr (2)=1 For I=3 To m Arr (I)=arr (I - 1) + arr (I - 2) 'here always when I=24 overflow Next Text1. Text=arr (m) End Sub
CodePudding user response:
VB6.0 by use of Integer range for - between 32768 and 32767 You this value the Fibonacci sequence of 46368 (24) Beyond the scope of the
Dim arr () As string, m As string,
And the true spelt wrong
CodePudding user response:
"Value" with integer, don't use String,
With Long, best if calculation number many, even "overflow", use type Double, Dim arr () As Long or Dim arr () As a Double A few other changes, with Long, or an Integer can be a huge difference,
CodePudding user response:
Agree with the first half of the upstairs, arr () with long, number theory aspect, is an integer, type double precision is not enough, the numerical everbright useless,
CodePudding user response:
If you want to show off in an ostentatious manner in front of your classmates can be arr () is defined as the variant and the back of the operation will be converted to a decimal data, thus, can calculate m to 139
Option Base 1 Private Sub Command1_Click () Dim arr () As the Variant, m As Currency, I, As Long As a Long 'For a=0 To Op1. Count - 1 'If Op1 (a). The Value=https://bbs.csdn.net/topics/ture Then 'm=Val (Op1) (a). The Caption) 'End If 'the Next a M=139 'm maximum values ReDim arr (m) Arr (1)=1 Arr (2)=1 For I=3 To m Arr (I)=CDec (arr (I - 1)) + CDec (arr (I - 2)) Next Text1. Text=arr (m) End Sub
Finally the execution result is 50095301248058391139327916261