I started learning Visual Basic and ran into a problem. You need to make a character array and get a random value from this array into a variable. I just started learning Visual Basic, but in php it would look like:

$mass = array("lalka", "fsdfsd546", "heyt");//массив с названием $mass $per = array_rand($mass, 1);//Извлекаю из этого массива одно значение в переменную echo ($per);//Вывожу сообщение 

Please write how this code will look in Visual Basic.

  • started studying basic - finish studying basic. - strangeqargo

2 answers 2

Understand: Visual Basic and VB.NET are almost the same (the syntax is very similar), the difference is that VB.NET [Visual Basic .NET] works on the .NET Framework. You are requesting code for "Visual Basic 2010". Practically, this is it, this code will work in "Visual Basic 2008", "Visual Basic 2005", and even in "VS Express 2013 for Desktop" (which contains Visual Basic). Read the Visual Basic 6 / VB.NET / .NET Framework specification and definition. Again, better learn C # (also on the .NET Framework)!

The function itself:

 Public Function RandomWord() ' Случайное число Dim rnd As New Random() ' Ваш массив: Dim massive() As String = {"lalka", "fsdfsd546", "heyt"} ' Случайное число, ограниченное количеством строк массива Dim random As Integer = rnd.Next(massive.Length) ' Вернуть результат: Return massive(random) End Function 

Then use the function, the function returns a string:

 Dim randomword As String = RandomWord() 

And MessageBox.Show(randomword) conclusion using MessageBox.Show(randomword) , Console.WriteLine(randomword) or other

    Option

     Sub RndStr() Dim ArrStr() Dim sStr As String ArrStr = Array("lalka", "fsdfsd546", "heyt") Randomize sStr = ArrStr(Int((UBound(ArrStr) + 1) * Rnd)) MsgBox sStr End Sub