Solved

Strings

Posted on 2004-08-10
9
233 Views
Last Modified: 2010-04-23
i have this application which i use a picture box to display letters (A- Z).  I used x and y coordinated to create the letters.  I am having difficulty in trying to display a word or sentence to the picture box through a text box.  Should something like a String.ToCharArray() be used to reference each individual character or a string.chars to search the string??  I am really stuck here as how to solve this.

heres an example of the letter Capital S i have created

Private Sub S(ByVal C As Integer, ByVal R As Integer)
' C - Column
' R - Row
        Dim index As Integer
        Dim I As Integer

        'S-------------------------------------------------------------------
        For index = 0 To 2
            myRoadSign.SetLight(C, 1 + index + R, True)
        Next
        For I = 1 To 3
            myRoadSign.SetLight(C + I, 0 + R, True)

        Next
        myRoadSign.SetLight(C + I, 1 + R, True)

        For I = 0 To 2
            myRoadSign.SetLight(C + 4, I + 5 + R, True)

        Next
        For I = 1 To 3
            myRoadSign.SetLight(C + I, 8 + R, True)

        Next
        myRoadSign.SetLight(C + 0, 7 + R, True)
        For I = 1 To 3
            myRoadSign.SetLight(C + I, 4 + R, True)
        Next

    End Sub

I call the function like this with hard coded values Call S(11, 36 )
below is a small function to test if the letter is uppercase and then calls the S function dynamically.  this obviously doens't work

 Public Sub WLBoard(ByVal text As String)
Dim i As Integer = 0
While i <> -1
If text(i) = "S" Then ' error
upperA(xpos, ypos)
End If
End While
End Sub

I want to display the words or sentences dynamically.  Any help will be very much appreciated.  

gbilios


0
Comment
Question by:gbilios
  • 6
  • 3
9 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 130 total points
ID: 11769897
To access the individual characters in a string iteratively you would do something like this:

Public Sub WLBoard(ByVal text As String)
    Dim i As Integer
    Dim c As String
    For i = 0 To text.Length - 1
        c = text.Substring(i, 1)
        If c.equals("S") Then
            upperA(xpos, ypos)
        End If
    Next i
End Sub
0
 

Author Comment

by:gbilios
ID: 11769926
i appreciate your quick reply.  So if i added if else statements  for the entire alphabet, then me typing in a word would be displayed exactly as i have typed it in the textbox?

upperA(xpos, ypos)  'xpos is Columns and ypos is Rows

I have experimented with various ways but the most simplest would be

Col = Col + 6 ' moves the entire letter to the next column

I added 6 because i dont want the letters to sit ontop of each other.  Is there a function to detect spaces so that i can write sentences in the picture box.

Would there be an additional for loop to allow the x and y coordinates to be done dynamically instead of me hard coding it like this

upperA(0,36)

0
 

Author Comment

by:gbilios
ID: 11770154
i must of missed something . i modified the line of code :

upperA(xpos, ypos) to upperA(i*6, ypos)

This allows me to enter words and sentences.  prior doing this, there was no way telling or no way the characters or words would form without the column(s) incrementing .

i appreciate all your help

thank-you

gbilios
0
 

Author Comment

by:gbilios
ID: 11770864
I have one more query with the following code
Dim i As Integer
    Dim c As String
    For i = 0 To text.Length - 1
        c = text.Substring(i, 1)
        If c.equals("S") Then
            upperA(xpos, ypos)
        End If
    Next i
End Sub

i changed it to

   If c.Equals("A") Then
         Call A(col, row)

           col = col + 6
  else If col > 76 Then
            col = 0
                row = row + 11
            End If

The line Call A(col, row)

enables lines to be displayed when the text too long
With this modified code i am unable to enter spaces
if i change the line Call A(i*6) then that solves it but does not allow me to have multiple lines

Can anyone please help
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 11772248
What is the difference between upperA() and A()?

Can you post some more complete code?  I'm sure we can get it working...

Idle_Mind
0
 

Author Comment

by:gbilios
ID: 11773679
Sorry for the missunderstabding
the program does the basic things which is display the characters to the picture box

for example the sentence above and i keep typing till the end of the line , i should automatically goto the next line the code that does this is

if col > 76 then
row = row + 11 'goto next line 11 rows down
col = 0 ' set column to position 0

A is Upper and lower which i am still doing is lowerA

Private Sub A(ByVal C As Integer, ByVal R As Integer) ' okay, should be upperA
        Dim index As Integer
        Dim I As Integer

        'A-------------------------------------------------------------------

        For index = 0 To 7
            myRoadSign.SetLight(C, 1 + index + R, True)
            myRoadSign.SetLight(C + 4, 1 + index + R, True)

        Next
        For I = 1 To 3
            myRoadSign.SetLight(C + I, 0 + R, True)
        Next

        For I = 1 To 3
            myRoadSign.SetLight(C + I, 4 + R, True)
        Next

    End Sub

    Private Sub lowerA(ByVal C As Integer, ByVal R As Integer)
        Dim index As Integer
        Dim I As Integer

        'a-------------------------------------------------------------------
        For index = 0 To 3

            myRoadSign.SetLight(C + 4, 5 + index + R, True)

        Next

        For index = 0 To 2


            myRoadSign.SetLight(C, 5 + index + R, True)

        Next
        For I = 0 To 2
            myRoadSign.SetLight(C + 1 + I, 4 + R, True)

        Next
        For I = 0 To 1
            myRoadSign.SetLight(C + 1 + I, 4 + R, True)
            myRoadSign.SetLight(C + 1 + I, 8 + R, True)
        Next
        myRoadSign.SetLight(C + 3, 7 + R, True)
       

    End Sub
0
 

Author Comment

by:gbilios
ID: 11773758
i accidentally hity the tab button , got sent without me finishing it

the previous message with the both uppercase and lowercase characters are created using x,y coordinates (columns and rows).

Public Sub WLBoard(ByVal text As String)
        Dim i As Integer
        Dim c As String
        Dim row As Integer = 0 ' Set the Row position to zero
        Dim col As Integer = 0 ' Set the Column position to zero

        For i = 0 To text.Length - 1

            c = text.Substring(i, 1)
            If col > 76 Then
                Call A(col, row)
                row = row + 11
                col = 0
            End If

            If c.Equals("A") Then

                Call A(col, row)

                col = col + 6

            End If

            If c.Equals("a") Then

                Call lowerA(col, row)

                col = col + 6

            End If
At this point i am worrying getting the basics done which is displaying text like i wrote this sentence.  
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 11775806
This what you looking for?

    Public Sub WLBoard(ByVal text As String)
        Dim i As Integer
        Dim c As String
        Dim row As Integer = 0 ' Set the Row position to zero
        Dim col As Integer = 0 ' Set the Column position to zero

        For i = 0 To text.Length - 1
            c = text.Substring(i, 1)
            Select Case c
                Case "A"
                    Call A(col, row)
                Case "a"
                    Call lowerA(col, row)
                Case "B"
                    Call B(col, row)
                Case "b"
                    Call lowerB(col, row)

                    ' add more Case statements for
                    ' all of your other letters in here

                Case Else
                    MsgBox(c, MsgBoxStyle.Information, "Undefined Letter")
            End Select
            col = col + 6
            If col > 76 Then
                row = row + 11
                col = 0
            End If
        Next i
    End Sub
0
 

Author Comment

by:gbilios
ID: 11780674
That is precisely what i did.  Creating the letters and getting them to the picture box wasn't the problem.  It was 'spaces' and the carriage returns i was having problems.    
I solved that problem (spaces & CR) and it was alot simple than i thought.  I worked out exactly what needed to be done.  
I added the if statement
if c.Equals(" ") ' if its a space then add a space
   col = col + 6 ' go six columns to the right
end if

or the case statement

case " "
  col = col + 6

i appreciate your help.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now