Results 1 to 5 of 5

Thread: [RESOLVED] (newbie question) "Use compound assignment" in a simple program

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2014
    Posts
    7

    Post [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

  2. #2
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    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.
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2014
    Posts
    7

    Post Re: (newbie question) "Use compound assignment" in a simple program

    Quote Originally Posted by David Anton View Post
    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.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2014
    Posts
    7

    Resolved Re: (newbie question) "Use compound assignment" in a simple program

    Quote Originally Posted by paul.e.king View Post
    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.

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: [RESOLVED] (newbie question) "Use compound assignment" in a simple program

    VB wouldn't normally just change that for no reason...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width