Click here to Skip to main content
15,879,683 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: DEVELOPING A HOTEL RESERVATION SYSTEM Pin
Colin Angus Mackay30-Jul-09 10:02
Colin Angus Mackay30-Jul-09 10:02 
Questionhow to add sql statement in databinding?, vb 2005 Pin
wongth75-Jul-09 20:23
wongth75-Jul-09 20:23 
Questionproblem with delete button ..vb 2005 Pin
wongth75-Jul-09 20:17
wongth75-Jul-09 20:17 
QuestionPrint Out Problem in Billing system??? Pin
JC.KaNNaN5-Jul-09 19:32
JC.KaNNaN5-Jul-09 19:32 
AnswerRe: Print Out Problem in Billing system??? Pin
EliottA6-Jul-09 2:53
EliottA6-Jul-09 2:53 
QuestionWrite to a word doc which is already open. Pin
Musa Biralo5-Jul-09 16:47
Musa Biralo5-Jul-09 16:47 
AnswerRe: Write to a word doc which is already open. Pin
Christian Graus5-Jul-09 17:03
protectorChristian Graus5-Jul-09 17:03 
QuestionSorting a structure array Pin
Jacob Dixon5-Jul-09 11:53
Jacob Dixon5-Jul-09 11:53 
I need some assistance in sorting a structure array...

I am reading words from a text file and need to store them in a array:
Structure Translate
    Dim English As String
    Dim French As String
    Dim German As String
End Structure


Dim TWord(16) As Translate


I then read the text file.. which basically goes from English, to French, to German.
So the first line in the text file is the English word YES, the second line is OUI (French) which means YES and the third is JA (German) which means YES in English as well. So what I have to do it put these ina structured array.

fs = New FileStream("TranslateC.txt", FileMode.Open, FileAccess.Read)
sr = New StreamReader(fs)

count = 0
Do While sr.Peek() >= 0

    TWord(count).English = sr.ReadLine()
    TWord(count).French = sr.ReadLine()
    TWord(count).German = sr.ReadLine()
    count = count + 1
Loop
sr.Close()


Now that I have that.. they want me to sort the english words?!? This is where I get completely lost. I found code earlier that helped me and it sorted the english words from A to Z but none of the others. So the translated words did not match up.


*** Could anyone point me to the correct location of a good tutorial on this? ***


I did the project first hand (That works!) but used jagged arrays instead:
Peronsally I like this way better but according to the project it is not HOW they wanted it done:
Imports System.IO

Public Class Form1

    Dim TranslateWords(15)() As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim fs As FileStream
        Dim sr As StreamReader
        Dim count As Integer

        fs = New FileStream("TranslateC.txt", FileMode.Open, FileAccess.Read)
        sr = New StreamReader(fs)

        count = 0
        Do While sr.Peek() >= 0
            Dim read = sr.ReadLine()

            If read <> Nothing Then
            Dim words As String() = read.Split(",")
            TranslateWords(count) = New String() {words(0), words(1), words(2)}
            End If

            count = count + 1
        Loop
        sr.Close()
    End Sub

    Private Sub SortArray()

    End Sub

    Private Sub btnTranslate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTranslate.Click
        Dim sentence As String = txtEnglish.Text
        Dim splitSentence As String() = sentence.Split(New Char() {" "c})
        Dim count As Integer

        txtTranslated.Text = ""

        If radioFrench.Checked Then

            For Each word As String In splitSentence
                Dim translated As Boolean

                translated = False
                For count = 0 To 15
                    If TranslateWords(count)(0).ToLower() = word.ToLower() Then
                        txtTranslated.Text += TranslateWords(count)(1) + " "
                        translated = True
                    End If
                Next

                If translated = False Then
                    txtTranslated.Text += word + " "
                End If

            Next

        ElseIf radioGerman.Checked Then

            For Each word As String In splitSentence
                Dim translated As Boolean

                translated = False
                For count = 0 To 15
                    If TranslateWords(count)(0).ToLower() = word.ToLower() Then
                        txtTranslated.Text += TranslateWords(count)(2) + " "
                        translated = True
                    End If
                Next

                If translated = False Then
                    txtTranslated.Text += word + " "
                End If

            Next

        Else
            MsgBox("You must select French or German before trying to translate", MsgBoxStyle.Information)
        End If

    End Sub
End Class

AnswerRe: Sorting a structure array Pin
Luc Pattyn5-Jul-09 12:40
sitebuilderLuc Pattyn5-Jul-09 12:40 
GeneralRe: Sorting a structure array Pin
Jacob Dixon5-Jul-09 12:44
Jacob Dixon5-Jul-09 12:44 
AnswerRe: Sorting a structure array Pin
Gideon Engelberth5-Jul-09 12:44
Gideon Engelberth5-Jul-09 12:44 
GeneralRe: Sorting a structure array Pin
Jacob Dixon5-Jul-09 13:52
Jacob Dixon5-Jul-09 13:52 
GeneralRe: Sorting a structure array Pin
Gideon Engelberth5-Jul-09 15:56
Gideon Engelberth5-Jul-09 15:56 
GeneralRe: Sorting a structure array Pin
Jacob Dixon5-Jul-09 15:59
Jacob Dixon5-Jul-09 15:59 
GeneralRe: Sorting a structure array Pin
Luc Pattyn6-Jul-09 0:46
sitebuilderLuc Pattyn6-Jul-09 0:46 
QuestionDrag&Drop problem Pin
The real $M@5-Jul-09 0:17
The real $M@5-Jul-09 0:17 
AnswerRe: Drag&Drop problem Pin
Mycroft Holmes5-Jul-09 2:14
professionalMycroft Holmes5-Jul-09 2:14 
GeneralRe: Drag&Drop problem Pin
Henry Minute5-Jul-09 4:18
Henry Minute5-Jul-09 4:18 
GeneralRe: Drag&Drop problem Pin
Mycroft Holmes5-Jul-09 14:10
professionalMycroft Holmes5-Jul-09 14:10 
AnswerRe: Drag&Drop problem Pin
Alan N5-Jul-09 4:05
Alan N5-Jul-09 4:05 
GeneralRe: Drag&Drop problem Pin
The real $M@5-Jul-09 22:04
The real $M@5-Jul-09 22:04 
QuestionAccess Database Path using vb.net[modified] Pin
mirzamujib4-Jul-09 23:09
mirzamujib4-Jul-09 23:09 
AnswerRe: Access Database Path using vb.ne Pin
dan!sh 5-Jul-09 2:30
professional dan!sh 5-Jul-09 2:30 
GeneralRe: Access Database Path using vb.ne Pin
mirzamujib5-Jul-09 3:58
mirzamujib5-Jul-09 3:58 
GeneralRe: Access Database Path using vb.ne Pin
dan!sh 5-Jul-09 5:19
professional dan!sh 5-Jul-09 5:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.