Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8705307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:19:43+00:00 2026-06-13T03:19:43+00:00

I am having a problem with my variables. I am receiving the value of

  • 0

I am having a problem with my variables. I am receiving the value of the variable email through an argument from an external program. When inside the For Next loop it contains the correct value but when it exits the loop it suddenly has no value. How would I go about exiting the loop and maintaining the value of the email variable.

Option Strict On

Imports MySql.Data.MySqlClient
Imports System.Runtime.Serialization

Module jrConnect

    Sub Main(ByVal cmdArgs() As String)
        Dim cs As String = "serverinfo"
        Dim conn As New MySqlConnection(cs)
        Dim entID As String
        Dim email As String

        Dim returnValue As Integer = 0

        If cmdArgs.Length > 0 Then
            For argNum As Integer = 0 To UBound(cmdArgs, 1)
                Console.Write("your email address is " & cmdArgs(argNum))
                email = cmdArgs(argNum)
                'value of email is set
            Next argNum

        End If

        Try

            conn.Open()
            Console.Write("Connected")
            Dim stm As String = "SELECT ###### FROM ###### WHERE email =" & "'" & email & "'"
            'the email variable at this point has no value

            Dim cmd As MySqlCommand = New MySqlCommand(stm, conn)
            Dim reader As MySqlDataReader = cmd.ExecuteReader()

            While reader.Read()
                entID = reader.GetString(0)
            End While
            reader.Close()

            Dim stm2 = "SELECT value FROM ###### WHERE ###### = " & entID
            Dim cmd2 As MySqlCommand = New MySqlCommand(stm2, conn)
            Dim reader2 As MySqlDataReader = cmd2.ExecuteReader()
            Dim counter As Integer = 0

            While reader2.Read() And counter < 3
                Console.WriteLine(reader2.GetString(0) & "%")
                counter = counter + 1
            End While
            reader.Close()

        Catch ex As MySqlException
        Finally
            conn.Close()
        End Try

    End Sub

End Module

the error im getting….
http://hostthenpost.org/uploads/a66f3efbf2eba24cef0f4e8536111b54.png

I changed it up a bit and added all the db processes to a function and tried to just pass the email variable to the function but it is printing the email address but not sending it to the function. Here is the new code.

Option Strict Off

Imports MySql.Data.MySqlClient
Imports System.Runtime.Serialization

Module jrConnect

    Sub Main(ByVal cmdArgs() As String)
        Dim temp As String = "spkelly86@gmail.com"
        'MsgBox("The Main procedure is starting the application.")
        Dim returnValue As Integer = 0
        ' See if there are any arguments.
        If cmdArgs.Length > 0 Then
            temp = cmdArgs(0)
            Console.Write(temp & " IN VB!")
            DBConnect(temp)
        End If
        ' Insert call to appropriate starting place in your code.
        'MsgBox("The application is terminating.")




    End Sub

    Function DBConnect(ByVal email As String)

        Dim cs As String = "serverinfo"
        Dim conn As New MySqlConnection(cs)
        Dim entID As String
        Try

            conn.Open()
            Dim stm As String = "SELECT ****** FROM ******** WHERE email =" & "'" & email & "'"
            Dim cmd As MySqlCommand = New MySqlCommand(stm, conn)
            Dim reader As MySqlDataReader = cmd.ExecuteReader()

            While reader.Read()
                entID = reader.GetString(0)
            End While
            reader.Close()

            Dim stm2 = "SELECT value FROM ****** WHERE ****** = " & entID
            Dim cmd2 As MySqlCommand = New MySqlCommand(stm2, conn)
            Dim reader2 As MySqlDataReader = cmd2.ExecuteReader()
            Dim counter As Integer = 0

            While reader2.Read() And counter < 3
                Console.WriteLine(reader2.GetString(0) & "%")
                counter = counter + 1
            End While
            reader.Close()

        Catch ex As MySqlException
        Finally
            conn.Close()
        End Try
        Return 0
    End Function
End Module
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:19:44+00:00Added an answer on June 13, 2026 at 3:19 am

    You don’t exit the loop when the variable is set.

    Try this:

    Dim email As String = "dummy@email.com"
    For argNum As Integer = 0 To UBound(cmdArgs, 1)
        Console.Write("your email address is " & cmdArgs(argNum))
        email = cmdArgs(argNum)
        'value of email is set
        Exit For
    Next argNum
    

    or the equivalent:

    Dim email As String = "dummy@email.com"
    If cmdArgs.Length > 0 Then
        Console.Write("your email address is " & cmdArgs(0))
        email = cmdArgs(0)
    End If
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem with XSL variables. I know that once declared, the value
I seem to be having a problem creating new local variables inside a switch
i am having a problem, i am receiving an error which says undefined variable
I'm having a problem relating to storing a variable within Javascript. I have a
I am having a problem accessing a static const variable defined in my class
I'm facing a problem to solve this issue. I'm having a string variable, for
I'm currently having problems to execute a command from a shell variable. In general
I am having problems getting JBoss to inject an environment variable value into a
I'm having problems with retrieving multiple instances of a session variable from an InProc
I'm having some problem with my SQL syntax/escaping variables on my LAMP server. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.