-
Dec 24th, 2021, 01:04 PM
#1
Thread Starter
New Member
[RESOLVED] (newbie question) "Use compound assignment" in a simple program
Hi. There are some problems I am having regarding an error I am getting regarding something called a "compound assignment". Here is the code. I can't see for the life of me where anything may be the matter. For the record, this code is intended to be run in Windows, and is not a console app.
The program just takes a number from a text box, and uses it to
write a list of numbers in another text box. I can program in other languages, but am a newbie to Visual Basic.
Code:
Public Class Form1
Private Sub BtnCalc_Click(sender As Object, e As EventArgs)
Dim n As Int64 = Int64.Parse(TextBox1.Text)
RichTextBox1.Clear()
While (n <> 1)
If (n Mod 2 = 1) Then
' it is odd
n = n * 3 + 1
Else
' it is even
n = n / 2
End If
RichTextBox1.AppendText(Str(n))
End While
End Sub
End Class
The error message says the error occurs on Line 12, where there is the statement n = n/2. This seems to be a fatal error, as the program neither compiles nor runs. Any ideas?
Paul King
Last edited by paul.e.king; Dec 24th, 2021 at 11:58 PM.
Reason: Complete code
-
Dec 24th, 2021, 02:20 PM
#2
Re: (newbie question) "Use compound assignment" in a simple program
It both compiles and runs for me.
The issue about compound assignment is just a suggestion by Visual Studio - you can rewrite that statement as "n /= 2", but your version is still correct.
-
Dec 24th, 2021, 03:47 PM
#3
Thread Starter
New Member
Re: (newbie question) "Use compound assignment" in a simple program
Originally Posted by David Anton
It both compiles and runs for me.
The issue about compound assignment is just a suggestion by Visual Studio - you can rewrite that statement as "n /= 2", but your version is still correct.
I just compiled it again, and I am getting a different error:
Code:
error BC30420: 'Sub Main' was not found in 'Collatz'
I didn't change anything. When I set up the project, I didn't like saving the project to C: drive, so I chose a location on another drive. There was also a pop-up I got which said that the exe file that was "in my debug profile" doesn't exist -- which was a strange error. Where is this debug profile, and how can I change it?
Paul
Last edited by paul.e.king; Dec 24th, 2021 at 03:51 PM.
-
Dec 24th, 2021, 11:51 PM
#4
Thread Starter
New Member
Re: (newbie question) "Use compound assignment" in a simple program
Originally Posted by paul.e.king
I just compiled it again, and I am getting a different error:
Code:
error BC30420: 'Sub Main' was not found in 'Collatz'
I didn't change anything. When I set up the project, I didn't like saving the project to C: drive, so I chose a location on another drive. There was also a pop-up I got which said that the exe file that was "in my debug profile" doesn't exist -- which was a strange error. Where is this debug profile, and how can I change it?
Paul
It looks like VB made sub Main() my startup object in the debug configuration. I changed it to "Form1". This was under the "Debug|ProgName debug Properties" menu item. A tab of debug properties comes up,and you need to choose the "Application" tab, and change the setting for Startup Object near the bottom of that form.
-
Dec 25th, 2021, 12:17 AM
#5
Re: [RESOLVED] (newbie question) "Use compound assignment" in a simple program
VB wouldn't normally just change that for no reason...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|