Thursday, November 4, 2010

Thursday, November 4th 2010

Here is a program using .toCharArray


Module Module1

Sub Main()
Dim string1 As String = "Hello!"
Dim stopNow As Boolean = False

Call printChar(string1)

Do Until stopNow = True
' I used two functions in this code, getString() and stopOrNot()
string1 = getString()
Call printChar(string1)
stopNow = stopOrNot()
Loop





End Sub

Sub printChar(ByVal string1)

Dim charArray() As Char = string1.ToCharArray
For i = 0 To charArray.Length - 1
Console.WriteLine(charArray(i))
System.Console.Beep(20 * i + 37, 150)
Next
End Sub

Function getString()
Dim stringHere As String
Console.WriteLine("Please enter a string.")
stringHere = Console.ReadLine
Return (stringHere)
End Function

Function stopOrNot()
Dim stringHolder As String
Console.WriteLine("Would you like to enter another string?")
Console.WriteLine("Press enter to continue or else 'Q' to quit")
stringHolder = Console.ReadLine()
stringHolder = stringHolder.ToUpper
If stringHolder = "Q" Then
Return (True)
Else
Return (False)
End If
End Function
End Module


I got this to work but it was very very painful.


Imports System.IO

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim Di As New IO.DirectoryInfo("C:\users\Alfred\documents")
Dim filesList() As IO.FileInfo = Di.GetFiles("*.doc")

Dim fullText As String = ""

Dim fileInfo As IO.FileInfo


Dim fileNameArray(1000, 1) As String
Dim arrayCounter As Integer = 0

For Each fileInfo In filesList

fileNameArray(arrayCounter, 0) = fileInfo.Name

arrayCounter += 1
Next

Dim number As Integer = 1
For i = 0 To arrayCounter - 1
fileNameArray(i, 1) = number + i
Next




For i = 0 To arrayCounter - 1
fullText = fullText & fileNameArray(i, 1) & vbTab & fileNameArray(i, 0) & vbCrLf
Next

showScreen.Text = fullText


End Sub


Here is a program for saving a file



Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim SaveFile As New SaveFileDialog
SaveFile.FileName = ""
SaveFile.Filter = "Text Files (*.txt) | *.txt"
SaveFile.Title = "Save"
SaveFile.ShowDialog()
Try
Dim writeFile As New System.IO.StreamWriter(SaveFile.FileName)
writeFile.Write(RichTextBox1.Text)
writeFile.Close()
MsgBox("File Saved!")


Catch ex As Exception

End Try
End Sub


Here is another For loop



Option Strict On
Imports System

Module Module1

Sub Main()
Dim loopCounter As Integer
For loopCounter = 0 To 9
Console.WriteLine("loopCounter: {0}", loopCounter)

Next
Console.ReadLine()
End Sub


Here is yet another FOR loop, with > 1 steps


Option Strict On
Imports System

Module Module1

Sub Main()
Dim sum = 0, number As Integer

For number = 2 To 100 Step 2
sum += number
Console.WriteLine(sum)
System.Console.Beep(55 + number + 2, CInt(75 + (number / 2)))


Next

Console.WriteLine("The sum is " & sum & " Even integers from 2 to 100")
Console.ReadLine()

End Sub

End Module

No comments: