3 Replies - 1337 Views - Last Post: 25 October 2011 - 02:44 PM Rate Topic: -----

#1 mihaispr  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 114
  • Joined: 29-September 09

Using Variables in Visual Basic little problem

Posted 29 September 2009 - 10:24 AM

Hi everyone and thanks for reading my question!

I began to learn Visual Basic 2008 Express Edition and I want to display the message Hello to Eric,Mihai and Bogdan.

So the desired output after my first display will be:

Hello Eric
Hello Mihai
Hello Bogdan



Here's the full code here:

Module Module1

	Sub Main()
		Afisare() 'call subroutine(procedure) Afisare'
		Saluta("Eric") 'apel subrutina (procedura) Saluta'
		Saluta("Mihai") 'apel subrutina (procedura) Saluta'
		Saluta("Bogdan") 'apel subrutina (procedura) Saluta'
	End Sub

	Sub Afisare()
		Console.WriteLine("==Program utilizare variabile Visual Basic==")
		Console.WriteLine("")
		Console.ReadLine()
	End Sub

	Sub Saluta(ByVal salut As String) 'define variable as value '
		'variable as value is defined by ByVal keyword'
		Dim mesaj As String 'define string variable named mesaj'
		mesaj = "Hello" & salut 'concatenate strings'
		Console.WriteLine(mesaj)
		mesaj = Console.ReadLine()
	End Sub

End Module



I attach the full source here to be more specific:

http://www.flyupload...get?fid=5345056

I don't know what I've made wrong in my code I simply call in Main subroutine the function Saluta and I put as arguments Eric,Mihai and Bogdan so that he displays me :

Hello Eric
Hello Mihai
Hello Bogdan 



But it only displays my first message from Subroutine Afisare.

Any help would be apreciated!

Hope I detail well my problem! And sorry to disturb your time:(

Thanks in advance!

This post has been edited by mihaispr: 29 September 2009 - 10:27 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Using Variables in Visual Basic little problem

#2 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 429
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: Using Variables in Visual Basic little problem

Posted 29 September 2009 - 10:51 AM

It just looks like it only displays the first message because the program stops execution because of this line:

Console.ReadLine()



The execution stops and waits for your input.

Remove that line from both Afisare and Saluta methods and add it to the end of the Main method to keep the window open:

Module Module1

	Sub Main()
		Afisare() 'call subroutine(procedure) Afisare'
		Saluta("Eric") 'apel subrutina (procedura) Saluta'
		Saluta("Mihai") 'apel subrutina (procedura) Saluta'
		Saluta("Bogdan") 'apel subrutina (procedura) Saluta'
		Console.ReadLine()
	End Sub

	Sub Afisare()
		Console.WriteLine("==Program utilizare variabile Visual Basic==")
		Console.WriteLine("")
	End Sub

	Sub Saluta(ByVal salut As String) 'define variable as value '
		'variable as value is defined by ByVal keyword'
		Dim mesaj As String 'define string variable named mesaj'
		mesaj = "Hello" & salut 'concatenate strings'
		Console.WriteLine(mesaj)
	End Sub

End Module


Was This Post Helpful? 0
  • +
  • -

#3 DarenR  Icon User is online

  • D.I.C Lover

Reputation: 485
  • View blog
  • Posts: 3,265
  • Joined: 12-January 10

Re: Using Variables in Visual Basic little problem

Posted 25 October 2011 - 11:21 AM

Private Sub AddButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddButton.Click


        ' declare variables  

        Dim first As Integer

        Dim second As Integer

        Dim result As Integer



        ' retrieve numbers from TextBoxes  
        first = Val(TextBox1.Text)

        second = Val(TextBox2.Text)



        ' add two numbers 
        result = first + second



        ' display result in Label  

        Label4.Text = result

    End Sub


here this works

and make sure your button is named AddButton
Was This Post Helpful? 0
  • +
  • -

#4 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,507
  • Joined: 16-March 11

Re: Using Variables in Visual Basic little problem

Posted 25 October 2011 - 02:44 PM

He's writing a console application, not a forms app. I like to use multi-threading for reading input simultaneously without halting the flow of the code but that is neither here nor there.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1