Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

replacing text in a textbox with pictures

Posted on 2003-11-27
4
Medium Priority
?
490 Views
Last Modified: 2010-05-01
id like to make a program that converts a string to hiragana, i have all the pictures but i just need a piece of code that can replace tow or three characters at a time in a rich text box.

hitori ja nai yo

() means that its picture so it will become
(HI)(TO)(RI) (JA) (NA)(I) (YO)

kono mama, atenado nakute ii
(KO)(NO) (MA)(MA), (A)(TE)(NA)(DO) (NA)(KU)(TE) (I)(I)

as you can see it replaces the text with pictures, is this possible
0
Comment
Question by:Tai-San
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9833647
listening...
0
 
LVL 6

Expert Comment

by:mirzas
ID: 9837300
Yes.. could you post a list of all letter combinations that will be replaced by a picture.

There is an easy way to do this.
Rename all the pictures to the strings they represent eg. (KO) should be KO.bmp
and put them in the same directory

This code has no error handling, will work only if images exist in the given path
and if valid input strings are given in Text1

Option Explicit
Const IMAGES_DIRECTORY = "C:\images\"
Const iImageW = 32
Const iImageH = 32

Private Sub Command1_Click()
    Dim x As Integer
    Dim y As Integer
    Dim i As Integer
    Dim tempBfr As String
   
    x = 1
    y = iImageH  'picture height
   
    tempBfr = ""
    For i = 1 To Len(Text1.Text)
        tempBfr = tempBfr & Mid(Text1.Text, i, 1)
        If FileExists(IMAGES_DIRECTORY & tempBfr) Then
            Picture1.PaintPicture LoadPicture("C:\a.bmp"), x, y
            tempBfr = ""
            x = x + iImageW
            'y remains the same if you place picures side by side
        End If
    Next
End Sub


Private Function FileExists(sFile As String) As Boolean
     If UCase(Dir(sFile)) = UCase(sFile) Then
      FileExists = True
    Else
      FileExists = False
    End If
End Function
0
 
LVL 6

Accepted Solution

by:
mirzas earned 250 total points
ID: 9837305
Ups! I made a mistake

the Line

 Picture1.PaintPicture LoadPicture("C:\a.bmp"), x, y


should be

 Picture1.PaintPicture LoadPicture(IMAGES_DIRECTORY & tempBfr), x, y

Sorry
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 9838253
Took a little while to come up with a working example. In the below example, you'll need to change the following constants to test it for yourself: ImageDir, ImageExt, Image1, Image2 and Image3. You may also want to add more constants of Image* (*=#) or use an array. The below example selects the word it found an image to, and replaces it by pasting the image for it.

Form1:
---------------

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const WM_PASTE = &H302

Private Const ImageDir As String = "C:\Program Files\Microsoft Visual Studio\Common\Graphics\Bitmaps\Assorted\"
Private Const ImageExt As String = ".bmp"
Private Const Image1 As String = "club"
Private Const Image2 As String = "cup"
Private Const Image3 As String = "hand"
Private Sub Form_Load()
    RichTextBox1.Text = ""
End Sub
Private Sub RichTextBox1_Change()
    Call ConvertWords(RichTextBox1)
End Sub
Private Sub ConvertWords(ByVal RichTextBox As RichTextBox)
    Dim strArray() As String, iLoop As Integer, iStart As Integer, iEnd As Integer
    strArray = Split(RichTextBox.Text, " ")
    For iLoop = LBound(strArray) To UBound(strArray)
        iEnd = iEnd + Len(strArray(iLoop)) + IIf(iLoop < UBound(strArray), 1, 0)
        iStart = iEnd - Len(strArray(iLoop))
        Select Case LCase(strArray(iLoop))
            Case Image1
                RichTextBox.SelStart = iStart
                RichTextBox.SelLength = iEnd
                Call PasteImage(ImageDir & Image1 & ImageExt, RichTextBox.hwnd)
            Case Image2
                RichTextBox.SelStart = iStart
                RichTextBox.SelLength = iEnd
                Call PasteImage(ImageDir & Image2 & ImageExt, RichTextBox.hwnd)
            Case Image3
                RichTextBox.SelStart = iStart
                RichTextBox.SelLength = iEnd
                Call PasteImage(ImageDir & Image3 & ImageExt, RichTextBox.hwnd)
        End Select
    Next iLoop
End Sub
Private Sub PasteImage(ByVal strPath As String, ByVal lHandle As Long)
    Clipboard.Clear
    Call Clipboard.SetData(LoadPicture(strPath))
    Call SendMessage(lHandle, WM_PASTE, 0, 0)
End Sub

-----------

If you have the folder (VS6) I used for testing, then you can test it by typing one of the Image* strings such as "club", "cup" or "hand". When you space it, the word will be replaced by the image.  This may be what you're looking for, if not, sorry. :)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

636 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