Hack Forums
[.NET] Answer - > text -> answer - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Answer - > text -> answer (/showthread.php?tid=3010117)



Answer - > text -> answer - Xparn - Nov 10, 2012

Hi, im totally new in programming and trying to do some easy progs so i get a hang of it... im stuck and don't know how to do this;

Code
Module Module1

    Sub Main()

  Console.WriteLine("Vad heter din mamma?")
  Dim mamma As String = Console.ReadLine()
  Console.WriteLine("Vad heter din pappa?")
  Dim pappa As String = Console.ReadLine()
  Console.WriteLine("Din mamma heter " & mamma, Console.WriteLine("och" & pappa)
  Console.WriteLine()
  Console.ReadLine()
    End Sub

End Module

My question is how can i make it work? so that mamma (answer) then i write some text then pappa (answer2) is coming on the same line? I know i can put the answer etc ->
text: Answer
text: Answer2

but as you can see i tried to get the answer in the same line, how do i do it? Thanks in advance! :p


* - carrot223 - Nov 10, 2012

You do not need the second console.writeline on that line:
Code
Console.WriteLine("Din mamma heter " & mamma & " och " & pappa)
Or neater:
Code
Console.WriteLine("Din mamma heter {0} och {1}", mamma, pappa)



* - Xparn - Nov 10, 2012

(Nov 10, 2012 01:11 AM)carrot223 Wrote:  You do not need the second console.writeline on that line:
Code
Console.WriteLine("Din mamma heter " & mamma & " och " & pappa)
Or neater:
Code
Console.WriteLine("Din mamma heter {0} och {1}", mamma, pappa)

Yay! Damn thank you haha i kept trying i didn't get it to work.. now i get it :P
Even though the {0} is red as the text is, it does count the {-} as the dim value? learnt something new if so :)


* - carrot223 - Nov 10, 2012

Yes, that is correct, see example:

Code
dim name as string = "john"
dim age as string ="28"
console.writeline("{0} is {1} years old", name, age)
'output is : john is 28 years old



* - Xparn - Nov 10, 2012

(Nov 10, 2012 01:39 AM)carrot223 Wrote:  Yes, that is correct, see example:

Code
dim name as string = "john"
dim age as string ="28"
console.writeline("{0} is {1} years old", name, age)
'output is : john is 28 years old

I see! thanks... I will probably ask alot more in this forum, hope noone gets angry! 😝