Results 1 to 6 of 6

Thread: Converting a console code to VB forms

  1. #1
    New Member
    Join Date
    Sep 12
    Posts
    3

    Converting a console code to VB forms

    I have the following code (Console mode) I want to convert it to VB Forms, I appreciate your help, I'm not a programmer, I'm a computer network student and I need that code, thanks to any help, here is the code:


    Imports System.IO

    Module Module1

    Sub Main()
    Dim answerarray(0 To 5) As String
    Dim selection As Integer = 0
    Dim studentname As String
    Dim Answers As String
    Dim Inputfile As StreamReader
    Console.WriteLine(" Please enter your name ...")
    studentname = Console.ReadLine()
    While selection <= 5
    Console.WriteLine(" Enter your answer for question (" & selection + 1 & ")")
    answerarray(selection) = Console.ReadLine()
    selection = selection + 1
    End While
    Dim change As String
    Dim finish As Boolean = False
    While finish <> True
    Console.WriteLine(" Type 1 to change an answer on a specific question")
    Console.WriteLine(" Type 2 to finish the test")
    change = Console.ReadLine()
    If change = "1" Then
    Console.WriteLine(" Please enter question number to be cahnged")
    selection = Console.ReadLine()
    Console.WriteLine(" What is your new answer?")
    answerarray(selection - 1) = Console.ReadLine()
    ElseIf change = "2" Then
    Console.WriteLine(" Your answer will be saved now....")
    Dim myfile As StreamWriter
    myfile = File.CreateText("c:\" & studentname & "answers.txt")
    selection = 0
    While selection <= 5
    myfile.WriteLine(answerarray(selection))
    selection = selection + 1
    End While
    myfile.Close()
    finish = True
    ElseIf change <> "1" Or change <> "2" Then
    Console.WriteLine(" Invalid Entry, press to try again...")
    change = Console.ReadLine()
    End If
    End While

    Inputfile = File.OpenText("c:\" & studentname & "answers.txt")
    Answers = Inputfile.ReadToEnd()
    Inputfile.Close()
    Console.WriteLine(Answers)

    Console.WriteLine(" Press Enter to end the program....")
    Console.ReadLine()
    End
    End Sub


    End Module

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,501

    Re: Converting a console code to VB forms

    I'm not a programmer, I'm a computer network student
    That has to be the saddest thing I've read all day! For all kinds of reasons. As a sympathy ploy I fear it's likely to fall on stony ground round these parts.

  3. #3
    New Member
    Join Date
    Sep 12
    Posts
    3

    Re: Converting a console code to VB forms

    Thanks any way dunfiddlin, but I want to make myself clear, I don't ask 4 any sympathy, this is not a homework or project, just something I'm trying to do but I have very modest ability in programming, that is all about, if any one can help, thanks to him, but really I don't need further comments.
    Thanks 2 u all

  4. #4
    PowerPoster Edgemeal's Avatar
    Join Date
    Sep 06
    Location
    WindowFromPoint(x,y)
    Posts
    3,135

    Re: Converting a console code to VB forms

    Not tested but using an inputbox should work,....
    Code:
    Public Class Form1
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Dim answerarray(5) As String
            Dim selection As Integer = 0
            Dim change As String
            Dim finish As Boolean = False
    
            Dim studentname As String = InputBox("Please enter your name ...")
    
            While selection < answerarray.Length
                answerarray(selection) = InputBox("Enter your answer for question (" & (selection + 1).ToString & ")")
                selection = selection + 1
            End While
    
            While finish <> True
                change = InputBox("Type 1 to change an answer on a specific question" _
                       & vbCrLf & "Type 2 to finish the test")
    
                If change = "1" Then
                    selection = CInt(InputBox("Please enter question number to be changed"))
                    answerarray(selection - 1) = InputBox(" What is your new answer?")
                ElseIf change = "2" Then
                    MessageBox.Show("Your answers will be saved now....")
                    IO.File.WriteAllLines("c:\" & studentname & "answers.txt", answerarray)
                    finish = True
                Else
                    MessageBox.Show(" Invalid Entry, press to try again...")
                End If
            End While
    
            ' Show answers
            Dim Answers As String = IO.File.ReadAllText("c:\" & studentname & "answers.txt")
            MessageBox.Show(Answers)
            Me.Close()
        End Sub
    
    End Class

  5. #5
    New Member
    Join Date
    Sep 12
    Posts
    3

    Re: Converting a console code to VB forms

    Yes Sir
    It did worked, thanks so much, appreciate your help, have a nice day or good night Edgemeal

    Assiegh

  6. #6
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,501

    Re: Converting a console code to VB forms

    I have very modest ability in programming
    Which obviously you intend to do nothing about despite being a computer student (allegedly)? Edgemeal is far too generous in my opinion. It is generally the policy around here to expect some effort on your own behalf before someone simply does it for you!

    Oh well, I'm just glad I got out of the rat race before the next generation of network 'experts' who haven't a clue about how anything 'software' actually works get their feet under the table!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •