0

I am making a random word generator for use in my Global Studies class for a game with the Cyrillic alphabet. I found a VBA setup for PowerPoint 2016 to pull random words from a text file. The problem is, it won't show the Cyrillic. I have tried changing the encoding in the VBA Tools. I have made sure to try different encoding settings for the .txt file, but I can't seem to get actually Cyrillic letters in the label.

The VBA code that I'm using is:

Public myArray, Word1
Sub OnSlideShowPageChange(ByVal SSW As SlideShowWindow)
    If SSW.View.CurrentShowPosition = 2 Then
        Randomize
        Label1.Caption = ""

        Dim path
        path = ActivePresentation.path & "\words.txt"

        Open path For Input As #1
        filecontent = Input(LOF(1), #1)
        Close #1

        myArray = Split(filecontent, vbCrLf)
    End If
End Sub

Private Sub CommandButton1_Click()
    Word1 = Int((UBound(myArray)) * Rnd)
    Label1.Caption = myArray(Word1)
End Sub

Private Sub Label1_Click()
End Sub
SCB
  • 5,821
  • 1
  • 34
  • 43
Kazimierz
  • 13
  • 3
  • See if this answers your question. https://stackoverflow.com/questions/17698260/ms-word-vba-to-display-unicode-strings/17699668#17699668. It's likely a text encoding issue e.g. ASCII vs Unicode. – Ryan Wildry Dec 20 '17 at 01:28
  • Thanks. The only thing is that since I am not a programmer, I don't know how I would incorporate that information into what I am using. I am using code provided by a YouTube video for teachers to be able to use in their classes without needing to know how to code. – Kazimierz Dec 20 '17 at 03:10
  • For VBA to work correctly with unicode, you need to make Windows system changes. Need to change the Language for the Non-Unicode programs to match. – PatricK Dec 20 '17 at 05:54
  • And how do I do that? Simply download the language pack for the program? (For example, the editing language pack for PowerPoint?) – Kazimierz Dec 20 '17 at 13:08
  • UPDATE: When I changed the PowerPoint editing language to Russian, the VBA code just displayed the same jibberish. I had the selected UTF-8 for the encoding for the .txt. – Kazimierz Dec 20 '17 at 13:23

1 Answers1

0
Try reading a line at a time from the file rather than using LOF:

Function FileToString(sFileName as string) as String

    Dim FileNum As Integer
    Dim sBuf As String
    Dim sTemp as String

    FileToString = False    ' by default

    If ExistFile(sFileName ) Then
        FileNum = FreeFile
        sTemp = ""
        Open sFileName For Input As FileNum

        While Not EOF(FileNum)
            Line Input #FileNum, sBuf
            sTemp= sTemp & sBuf & vbCrLf
        Wend

        Close FileNum
        FileToString = sTemp

End Function
Steve Rindsberg
  • 14,442
  • 1
  • 29
  • 34