 |
|
VB.Net ผมจะเขียนโปรแกรมวาดสามเหลี่ยมด้วยดอกจันทร์ ยังไงดีครับ รบกวนพี่ๆแนะนำ แก้รูปใหม่แล้วนะครับ |
|
 |
|
|
 |
 |
|
แก้รูปครับ พอดีผมพิมพ์ถูกแล้วแต่แสดงในเวบผิดเลยอัพรูปลงใหม่ครับ ผมลองผิดลองถูกจนงงแล้วครับ รบกวนพี่ๆหน่วครับ ขอบคุณครับ

คือแบบอื่นได้หมดแล้วครับเหลือแบบนี้ งงมาก รบกวนพี่ๆแนะนทีครับ เป็น console app VB ครับ
อันนี้โค้ดที่ผมทำได้แล้ว เปนรูปอื่นครับ
Code
Module Module1
Sub Print(ByVal str, ByVal n)
For index As Integer = 1 To n
Console.Write(str)
Next
End Sub
Sub PrintLine(ByVal str, ByVal n)
Print(str, n)
Console.WriteLine()
End Sub
Sub Main()
For row As Integer = 1 To 6
For column As Integer = 1 To 6
Console.Write("* ")
Next
Console.WriteLine()
Next
For row As Integer = 1 To 6
PrintLine("* ", row)
Next
For row As Integer = 6 To 1 Step -1
PrintLine("* ", row)
Next
Console.ReadKey()
End Sub
End Module
Tag : .NET, Win (Windows App), Console App, VB.NET, VS 2008 (.NET 3.x), VS 2010 (.NET 4.x)
|
ประวัติการแก้ไข 2013-11-20 17:31:24 2013-11-21 22:32:15 2013-11-21 22:33:12
|
 |
 |
 |
 |
Date :
2013-11-20 17:30:30 |
By :
vbnet |
View :
13572 |
Reply :
13 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันนี้ทำเองเถอะนะ ไม่รู้แนะนำยังไง
ถ้าโค้ดให้นิดเดียวก็เฉลยแล้ว โปรแกรมแค่ 2-3 บรรทัดเอง
|
 |
 |
 |
 |
Date :
2013-11-21 09:14:53 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รบกวนจิงๆครับ ผมลองมา หลายครั้งมาก ยังไม่ได้ งงมากเลย รบกวนพี่ๆหน่อยนะคับ
|
 |
 |
 |
 |
Date :
2013-11-21 19:01:24 |
By :
vbnet |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

รูปที่ต้องการจริงๆเป็นแบบนี้นะครับขอเปลี่ยนรูปใหม่นะครับ รบกวนพี่ๆหน่อยนะครับ จะสั่งให้มันชิดขวายังไงดีครับ
|
ประวัติการแก้ไข 2013-11-21 22:38:21
 |
 |
 |
 |
Date :
2013-11-21 22:35:28 |
By :
vbnet |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Console.WriteLine(String.Format("{0, 6}", "*"));
|
 |
 |
 |
 |
Date :
2013-11-22 08:14:07 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าจะใส่ลูป for จะใส่ยังไงดีครับ แนะนำทีครับ รับค่า 6
Code
Console.WriteLine(String.Format("{0, 6}", "*"))
Console.WriteLine(String.Format("{0, 6}", "**"))
Console.WriteLine(String.Format("{0, 6}", "***"))
Console.WriteLine(String.Format("{0, 6}", "****"))
Console.WriteLine(String.Format("{0, 6}", "*****"))
Console.WriteLine(String.Format("{0, 6}", "******"))
ตอนนี้ผมลองไปมาก็ยังไม่ได้ครับ ช่วยทีครับพี่ๆ
Code
Sub Print2(ByVal str, ByVal n)
For index As Integer = 1 To n
Console.Write(String.Format("{0, 6}", ""))
Console.Write(str)
Next
End Sub
|
ประวัติการแก้ไข 2013-11-22 09:46:41 2013-11-22 09:54:35
 |
 |
 |
 |
Date :
2013-11-22 09:46:01 |
By :
vbnet |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

Code (VB.NET)
Module Module1
Sub Main()
For i As Integer = 1 To 6
Console.WriteLine(String.Format("{0, 6}", New String(Enumerable.Repeat(Of Char)("*", i).ToArray())))
Next
Console.WriteLine()
For i As Integer = [..จงเติมคำตอบที่ถูกต้อง..] To [..จงเติมคำตอบที่ถูกต้อง..] Step -1
Console.WriteLine(String.Format("{0, 6}", New String(Enumerable.Repeat(Of Char)("*", i).ToArray())))
Next
Console.WriteLine()
Console.Write("Press any key to continue...")
Console.ReadKey()
End Sub
End Module
|
 |
 |
 |
 |
Date :
2013-11-22 10:24:51 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้ได้แบบนี้แล้วครับ
Code
Module Module1
Sub Print(ByVal str, ByVal n)
For index As Integer = 1 To n
Console.Write(str)
Next
End Sub
Sub PrintLine(ByVal str, ByVal n)
Print(str, n)
Console.WriteLine()
End Sub
Sub Main()
Console.Write("Input*[1-10]: ")
Dim y As Integer = Console.ReadLine()
If y > 10 Or y < 1 Then
End
End If
Console.Write("Input picture[1-5]: ")
Dim x As Char = Console.ReadLine()
Select x
Case Is = "1"
For row As Integer = 1 To y
For column As Integer = 1 To y
Console.Write("* ")
Next
Console.WriteLine()
Next
Console.ReadKey()
End
Case Is = "2"
For row As Integer = 1 To y
PrintLine("* ", row)
Next
Console.ReadKey()
End
Case Is = "3"
For row As Integer = y To 1 Step -1
PrintLine("* ", row)
Next
Console.ReadKey()
End
Case Is = "4"
Console.ReadKey()
End
Case Is = "5"
Console.ReadKey()
End
End Select
Console.ReadKey()
End Sub
End Module
|
 |
 |
 |
 |
Date :
2013-11-22 10:26:45 |
By :
vbnet |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วครับ ขอบคุณพี่ ห้ามตอบเกินวันละ 2 กระทู้ มากๆนะครับ ผมไม่รู้จักคำสั่ง Enumerable.Repeat( พวกนี้เลย เหอะๆ ถึงว่าทำไมยากแบบนี้ 
Code
Module Module1
Sub Print(ByVal str, ByVal n)
For index As Integer = 1 To n
Console.Write(str)
Next
End Sub
Sub PrintLine(ByVal str, ByVal n)
Print(str, n)
Console.WriteLine()
End Sub
Sub Main()
Console.Write("Input*[1-10]: ")
Dim y As Integer = Console.ReadLine()
If y > 10 Or y < 1 Then
End
End If
Console.Write("Input picture[1-5]: ")
Dim x As Char = Console.ReadLine()
Select x
Case Is = "1"
For row As Integer = 1 To y
For column As Integer = 1 To y
Console.Write("* ")
Next
Console.WriteLine()
Next
Console.ReadKey()
End
Case Is = "2"
For row As Integer = 1 To y
PrintLine("* ", row)
Next
Console.ReadKey()
End
Case Is = "3"
For row As Integer = y To 1 Step -1
PrintLine("* ", row)
Next
Console.ReadKey()
End
Case Is = "4"
For i As Integer = 1 To y
Console.WriteLine(String.Format("{0, 11}", New String(Enumerable.Repeat(Of Char)("*", i).ToArray())))
Next
Console.WriteLine()
Console.ReadKey()
End
Case Is = "5"
For i As Integer = y To 1 Step -1
Console.WriteLine(String.Format("{0, 11}", New String(Enumerable.Repeat(Of Char)("*", i).ToArray())))
Next
Console.WriteLine()
Console.ReadKey()
End
End Select
Console.ReadKey()
End Sub
End Module
|
 |
 |
 |
 |
Date :
2013-11-22 10:37:18 |
By :
vbnet |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันไม่ยากหรอก ไม่จำเป็นต้องใช้ enumerable.repeat เลยก็ได้
ที่เราใช้เพราะแค่อยากเขียนโค้ดสั้นๆ เท่านั้นเอง
เอาแบบลูกทุ่งๆ ใช้แค่ for อย่างเดียวยังได้เลย ไม่ต้องใช้ format ด้วย
กลับไปฝึกกระบวนการ solv ปัญหาเยอะๆ เลย ถ้าโจทย์แบบนี้ทำไม่ได้
นายเรียนสายนี้ไม่รอดแน่นอน
Code (VB.NET)
Module Module1
Sub Main()
Console.Write("Input [1-10]: ")
Dim num As Integer
Dim isNum As Boolean = Integer.TryParse(Console.ReadLine(), num)
Dim format As String = "{0, " & num.ToString() & "}"
Dim message As String = "Press any key to continue..."
Console.WriteLine()
If isNum Then
If num > 0 AndAlso num <= 10 Then
For i As Integer = 1 To num
Console.WriteLine(String.Format(format, New String(Enumerable.Repeat(Of Char)("*", i).ToArray())))
Next
Console.WriteLine()
For i As Integer = num To 1 Step -1
Console.WriteLine(String.Format(format, New String(Enumerable.Repeat(Of Char)("*", i).ToArray())))
Next
Console.WriteLine()
Else
message = "ERROR: Input range must between 1-10."
End If
Else
message = "ERROR: Cann't convert to integer."
End If
Console.Write(message)
Console.ReadKey()
End Sub
End Module
ให้ไปเป็นตัวอย่าง โค้ดเราทำงานได้เหมือนนาย แต่ของเราสั่นกว่านายเยอะเลย
|
 |
 |
 |
 |
Date :
2013-11-22 10:51:17 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แบบไม่ได้ใช้ format กับ enumerable.repeat
ใช้แค่ for กับ if
Code (VB.NET)
Module Module1
Sub Main()
Console.Write("Input [1-10]: ")
Dim num As Integer
Dim isNum As Boolean = Integer.TryParse(Console.ReadLine(), num)
Dim format As String = "{0, " & num.ToString() & "}"
Dim message As String = "Press any key to continue..."
Console.WriteLine()
If isNum Then
If num > 0 AndAlso num <= 10 Then
For i As Integer = 1 To num
For j As Integer = 1 To num
If j < num - i + 1 Then
Console.Write(" ")
Else
Console.Write("*")
End If
Next
Console.WriteLine()
Next
Console.WriteLine()
For i As Integer = 1 To num
For j As Integer = 1 To num
If j < i Then
Console.Write(" ")
Else
Console.Write("*")
End If
Next
Console.WriteLine()
Next
Console.WriteLine()
Else
message = "ERROR: Input range must between 1-10."
End If
Else
message = "ERROR: Cann't convert to integer."
End If
Console.Write(message)
Console.ReadKey()
End Sub
End Module
|
 |
 |
 |
 |
Date :
2013-11-22 11:18:56 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูนะค่ะ หนูเองก็ไม่รู้เรื่องอะไรมาก แต่พอดี วันนี้ เรียนเรื่องนี้พอดี 

|
 |
 |
 |
 |
Date :
2014-11-12 19:52:24 |
By :
misaza2127 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2014-11-12 19:53:43 |
By :
misaza2127 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|