none
Problem of creating text file and write in that text file. RRS feed

  • Question

  • Hi,

    The following code does not create the text file and I don't know why.

    Dim file As System.IO.StreamWriter
                If My.Settings.FileName1 = "" Then
                    file = My.Computer.FileSystem.OpenTextFileWriter("D:\Untitled.txt", True)
                Else
                    file = My.Computer.FileSystem.OpenTextFileWriter("D:\" & My.Settings.FileName1 & ".txt", True)
                End If
                file.WriteLine(TV)
                file.WriteLine(Str2007)
                file.Close()

    Please advice

    Kind Regards,


    Hany Metry

    Tuesday, November 12, 2019 3:25 PM

Answers

  • Hi,

    The following code is the correct code:

    Dim file As System.IO.StreamWriter
            Dim str2007 As String
    44:     If My.Settings.FileName1 = "" Then
                str2007 = "File: Untitled.epcol"
            Else
                str2007 = "File: " & My.Settings.FileName1
            End If
            Dim str601 As String
            Dim str60 As String
            str601 = InputBox("Choose textfile Name and its Path without extension", "Textfile Name and its Path without extension", "D:\untitled", , )
            str60 = str601
            If IO.File.Exists(str601 & ".txt") Then
                    Dim msgRslt As MsgBoxResult = MsgBox("File is exist, replace it now?", (MsgBoxStyle.YesNo))
                    If msgRslt = MsgBoxResult.Yes Then
                        My.Computer.FileSystem.DeleteFile(str60 & ".txt")
                        file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True)
                        'Else
                        file.WriteLine(TV)
                        file.WriteLine(str2007)
                    Else
                        MsgBox("File not created", CType(MessageBoxButtons.OK, MsgBoxStyle))
                        GoTo 44
                    End If
                Else
                    file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True)
                    file.WriteLine(TV)
                    file.WriteLine(str2007)
                End If
            End Sub
    The answer of Input Box by cancel means that the user is agree for the default name and path for the text file. 

    But still last 7 lines of text file not shown in the note pad but that is other problem not related to visual studio or visual basic and any how I will ask question in separate thread.


    Hany Metry



    • Marked as answer by Hany Metry Wednesday, November 13, 2019 4:14 PM
    • Unmarked as answer by Hany Metry Wednesday, November 13, 2019 4:18 PM
    • Marked as answer by Hany Metry Wednesday, November 13, 2019 4:28 PM
    • Edited by Hany Metry Wednesday, November 13, 2019 4:43 PM But still last 7 lines of text file not shown in the note pad but that is other problem not related to visual studio or visual basic and any how I will ask question in separate thread.
    Wednesday, November 13, 2019 4:13 PM
  • Hi,

    The following code is the correct code:

    Dim file As System.IO.StreamWriter
            Dim str2007 As String
    44:     If My.Settings.FileName1 = "" Then
                str2007 = "File: Untitled.epcol"
            Else
                str2007 = "File: " & My.Settings.FileName1
            End If
            Dim str601 As String
            Dim str60 As String
            str601 = InputBox("Choose textfile Name and its Path without extension", "Textfile Name and its Path without extension", "D:\untitled", , )
            str60 = str601
            If IO.File.Exists(str601 & ".txt") Then
                    Dim msgRslt As MsgBoxResult = MsgBox("File is exist, replace it now?", (MsgBoxStyle.YesNo))
                    If msgRslt = MsgBoxResult.Yes Then
                        My.Computer.FileSystem.DeleteFile(str60 & ".txt")
                        file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True)
                        'Else
                        file.WriteLine(TV)
                        file.WriteLine(str2007)
                    Else
                        MsgBox("File not created", CType(MessageBoxButtons.OK, MsgBoxStyle))
                        GoTo 44
                    End If
                Else
                    file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True)
                    file.WriteLine(TV)
                    file.WriteLine(str2007)
                End If
            End Sub
    The answer of Input Box by cancel means that the user is agree for the default name and path for the text file. 

    But still last 7 lines of text file not shown in the note pad but that is other problem not related to visual studio or visual basic and any how I will ask question in separate thread.


    Hany Metry



    Hi All,

    I am thinking to have two input boxes, one for the file path and other one for file name to be sure that the user don't enter a wrong file path (that there will be massage box, if the file path not exist) but still there will be a problem if the user enter again file path with file name at the second input box? what will be the massage box? (may be I will have massage box of some characters should not be included in file name like /  :   ) 

    Maybe tomorrow, I will think enough for that point.

    Kind Regards,


    Hany Metry

    Hi All,

    Maybe also instead of two input box, it will be one input box + Folder Browser Dialog.

    Kind Regards,


    Hany Metry

    • Marked as answer by Hany Metry Thursday, November 14, 2019 6:30 AM
    Wednesday, November 13, 2019 10:53 PM
  • Hi All,

    Below is not final code that I still have a small problem is how to prevent the character " to be chosen from file name.

    Dim file As System.IO.StreamWriter Dim str2007 As String 44: If My.Settings.FileName1 = "" Then str2007 = "File: Untitled.epcol" Else str2007 = "File: " & My.Settings.FileName1 End If TV = "Licensed to :Orascom Construction" Dim str601 As String Dim str601a As String Dim str60 As String Dim path As String Dim Letter As String FolderBrowserDialog1.ShowDialog() path = FolderBrowserDialog1.SelectedPath 45: str601a = InputBox("Choose textfile Name without Path and without extension", "Textfile Name without Path and without extension", "untitled", , )

    If str601a.Length > 25 Then
                MsgBox("Character length shall not exceed 25", CType(MessageBoxButtons.OK, MsgBoxStyle))
                GoTo 45
            End If

    For xf As Integer = 0 To str601a.Length - 1 Letter = str601a.Substring(xf, 1) If xf > 0 Then GoTo 46 If IsNumeric(str601a.Substring(0, 1)) Then MsgBox("First character must not be a Numeric", CType(MessageBoxButtons.OK, MsgBoxStyle)) GoTo 45 End If 46: If Letter.Contains(".") = True Or Letter.Contains("/") Or Letter.Contains("\") Or Letter.Contains("?") Or Letter.Contains("!") Or Letter.Contains("@") Or Letter.Contains("#") Or Letter.Contains("$") Or Letter.Contains("%") Or Letter.Contains("^") Or Letter.Contains("&") Or Letter.Contains("*") Or Letter.Contains("(") Or Letter.Contains(")") Or Letter.Contains("+") Or Letter.Contains("=") Or Letter.Contains("<") Or Letter.Contains(">") Or Letter.Contains(":") Or Letter.Contains("'") Or Letter.Contains("|") Or Letter.Contains("_") Or Letter.Contains("-") Or Letter.Contains("{") Or Letter.Contains("[") Or Letter.Contains("}") Or Letter.Contains("]") Or Letter.Contains(";") Or Letter.Contains(",") Or Letter.Contains("`") Or Letter.Contains("~") Or Letter.Contains(" ") Then MsgBox("Character is not allowed", CType(MessageBoxButtons.OK, MsgBoxStyle)) GoTo 45 End If Next str601 = path & str601a str60 = str601 If IO.File.Exists(str601 & ".txt") Then Dim msgRslt As MsgBoxResult = MsgBox("File is exist, replace it now?", (MsgBoxStyle.YesNo)) If msgRslt = MsgBoxResult.Yes Then My.Computer.FileSystem.DeleteFile(str60 & ".txt") file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True) 'Else file.WriteLine(TV) file.WriteLine(str2007) Else MsgBox("File not created", CType(MessageBoxButtons.OK, MsgBoxStyle)) GoTo 44 End If Else file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True) file.WriteLine(TV) file.WriteLine(str2007) End If


    Kind Regards,


    Hany Metry




    • Marked as answer by Hany Metry Thursday, November 14, 2019 6:30 AM
    • Edited by Hany Metry Thursday, November 14, 2019 7:30 AM Below is not final code that I still have a small problem is how to prevent the character " to be chosen from file name.
    Thursday, November 14, 2019 6:21 AM
  • Hi All,

    Below is not final code that I still have a small problem is how to prevent the character " to be chosen from file name.

    Dim file As System.IO.StreamWriter Dim str2007 As String 44: If My.Settings.FileName1 = "" Then str2007 = "File: Untitled.epcol" Else str2007 = "File: " & My.Settings.FileName1 End If TV = "Licensed to :Orascom Construction" Dim str601 As String Dim str601a As String Dim str60 As String Dim path As String Dim Letter As String FolderBrowserDialog1.ShowDialog() path = FolderBrowserDialog1.SelectedPath 45: str601a = InputBox("Choose textfile Name without Path and without extension", "Textfile Name without Path and without extension", "untitled", , )

    If str601a.Length > 25 Then
                MsgBox("Character length shall not exceed 25", CType(MessageBoxButtons.OK, MsgBoxStyle))
                GoTo 45
            End If

    For xf As Integer = 0 To str601a.Length - 1 Letter = str601a.Substring(xf, 1) If xf > 0 Then GoTo 46 If IsNumeric(str601a.Substring(0, 1)) Then MsgBox("First character must not be a Numeric", CType(MessageBoxButtons.OK, MsgBoxStyle)) GoTo 45 End If 46: If Letter.Contains(".") = True Or Letter.Contains("/") Or Letter.Contains("\") Or Letter.Contains("?") Or Letter.Contains("!") Or Letter.Contains("@") Or Letter.Contains("#") Or Letter.Contains("$") Or Letter.Contains("%") Or Letter.Contains("^") Or Letter.Contains("&") Or Letter.Contains("*") Or Letter.Contains("(") Or Letter.Contains(")") Or Letter.Contains("+") Or Letter.Contains("=") Or Letter.Contains("<") Or Letter.Contains(">") Or Letter.Contains(":") Or Letter.Contains("'") Or Letter.Contains("|") Or Letter.Contains("_") Or Letter.Contains("-") Or Letter.Contains("{") Or Letter.Contains("[") Or Letter.Contains("}") Or Letter.Contains("]") Or Letter.Contains(";") Or Letter.Contains(",") Or Letter.Contains("`") Or Letter.Contains("~") Or Letter.Contains(" ") Then MsgBox("Character is not allowed", CType(MessageBoxButtons.OK, MsgBoxStyle)) GoTo 45 End If Next str601 = path & str601a str60 = str601 If IO.File.Exists(str601 & ".txt") Then Dim msgRslt As MsgBoxResult = MsgBox("File is exist, replace it now?", (MsgBoxStyle.YesNo)) If msgRslt = MsgBoxResult.Yes Then My.Computer.FileSystem.DeleteFile(str60 & ".txt") file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True) 'Else file.WriteLine(TV) file.WriteLine(str2007) Else MsgBox("File not created", CType(MessageBoxButtons.OK, MsgBoxStyle)) GoTo 44 End If Else file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True) file.WriteLine(TV) file.WriteLine(str2007) End If


    Kind Regards,


    Hany Metry




    45:     str601a = InputBox("Choose textfile Name without Path and without extension", "Textfile Name without Path and without extension", "untitled", , )
            If str601a.Length > 25 Then
                MsgBox("Character length shall not exceed 25", CType(MessageBoxButtons.OK, MsgBoxStyle))
                GoTo 45
            End If
            For xf As Integer = 0 To str601a.Length - 1
                Letter = str601a.Substring(xf, 1)
                If xf > 0 Then GoTo 46
                If IsNumeric(str601a.Substring(0, 1)) Then
                    MsgBox("First character must not be a Numeric", CType(MessageBoxButtons.OK, MsgBoxStyle))
                    GoTo 45
                End If
    46:         If Letter.Contains(".") = True Or Letter.Contains("/") Or Letter.Contains("\") Or Letter.Contains("?") Or Letter.Contains("!") Or Letter.Contains("@") Or Letter.Contains("#") Or Letter.Contains("$") Or Letter.Contains("%") Or Letter.Contains("^") Or Letter.Contains("&") Or Letter.Contains("*") Or Letter.Contains("(") Or Letter.Contains(")") Or Letter.Contains("+") Or Letter.Contains("=") Or Letter.Contains("<") Or Letter.Contains(">") Or Letter.Contains(":") Or Letter.Contains("'") Or Letter.Contains("|") Or Letter.Contains("_") Or Letter.Contains("-") Or Letter.Contains("{") Or Letter.Contains("[") Or Letter.Contains("}") Or Letter.Contains("]") Or Letter.Contains(";") Or Letter.Contains(",") Or Letter.Contains("`") Or Letter.Contains("~") Or Letter.Contains(" ") Or Letter.Contains(Chr(34)) Then
                    MsgBox("Character is not allowed", CType(MessageBoxButtons.OK, MsgBoxStyle))
                    GoTo 45
                End If
            Next

    Hi All,

    That is the final code by replacing that part from the above post.

    to prevent double quote " the only way is to write       Or Letter.Contains(Chr(34))   that double quote code is 34 according to ASCII.

    Kind Regards,


    Hany Metry

    • Marked as answer by Hany Metry Thursday, November 14, 2019 12:29 PM
    Thursday, November 14, 2019 12:28 PM

All replies

  • Hi

    Yes it does! The fault is that the owner needs to learn to debug.

    Here is YOUR code, only amended for testing purposes and this works fine, it will create the file if it doesn't exist, and it will append the lines if it does exist.

    Test this code and then scratch your head for a while before posting again.

    You will need to edit to suit your system - I just used the DeskTop for testing purposes.

    	Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    		Dim p As String = "C:\Users\lesha\Desktop\"
    		Dim MySettingsFilename1 As String = ""
    
    		Dim file As IO.StreamWriter
    		If MySettingsFilename1 = "" Then
    			file = My.Computer.FileSystem.OpenTextFileWriter(p & "Untitled.txt", True)
    		Else
    			file = My.Computer.FileSystem.OpenTextFileWriter(p & MySettingsFilename1 & ".txt", True)
    		End If
    		file.WriteLine("Line 1")
    		file.WriteLine("Line 2")
    		file.Close()
    	End Sub


    Regards Les, Livingston, Scotland

    Tuesday, November 12, 2019 3:48 PM
  • Hi Leshay,

    I forget to told you that code written in form load.

    After debug, I find that the code path at  the following line.

    file = My.Computer.FileSystem.OpenTextFileWriter("D:\" & My.Settings.FileName1 & ".txt", True)

    and then does not complete to write in the next step because the text file does not created.

    Kind Regards,


    Hany Metry

    Tuesday, November 12, 2019 4:19 PM
  • Hi

    You DID set a breakpoint on that line and examine what

    My.Settings.FileName1

    was = didn't you? So was it as expected?


    Regards Les, Livingston, Scotland

    Tuesday, November 12, 2019 4:24 PM
  • Hello,

    Here is a simple example which offers an alternative to your current code. 

    If not interested in a different idea stop here.

    • An assertion is done in one line to select the file name
    • The path uses Path.Combine which adds any backslashes if needed
    • The StreamWriter will close automatically
    • Note the check for file exists which provides the append functionality
    Imports System.IO
    
    Public Class Form1
        Private Sub WriteToFileButton_Click(sender As Object, e As EventArgs) Handles WriteToFileButton.Click
    
            Dim fileName As String =
                    If(String.IsNullOrWhiteSpace(My.Settings.FileName1),
                        Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SomeFile.txt"),
                        Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AnotherFile.txt"))
    
            Using writer = New StreamWriter(fileName, CBool(IIf(File.Exists(fileName), True, False)))
                writer.WriteLine("one")
                writer.WriteLine("two")
            End Using
        End Sub
    
    End Class
     

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange


    Tuesday, November 12, 2019 4:27 PM
    Moderator
  • Hi Karen

    Just what is needed, a copy and paste solution ...................


    Regards Les, Livingston, Scotland

    Tuesday, November 12, 2019 4:36 PM
  • Hi Leshay,

    I forget to told you that code written in form load.

    After debug, I find that the code path at  the following line.

    file = My.Computer.FileSystem.OpenTextFileWriter("D:\" & My.Settings.FileName1 & ".txt", True)

    and then does not complete to write in the next step because the text file does not created.

    Kind Regards,


    Hany Metry

    Hi Hany,

    You may not be aware of this that there are cases where form load swallows runtime exceptions and sometimes does unpredictable things in form lpad. Now this may or may not help but consider moving form load code to the form shown event.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, November 12, 2019 4:38 PM
    Moderator
  • Hi Leshay,

    I forget to told you that code written in form load.

    After debug, I find that the code path at  the following line.

    file = My.Computer.FileSystem.OpenTextFileWriter("D:\" & My.Settings.FileName1 & ".txt", True)

    and then does not complete to write in the next step because the text file does not created.

    Kind Regards,


    Hany Metry

    Hi Hany,

    You may not be aware of this that there are cases where form load swallows runtime exceptions and sometimes does unpredictable things in form lpad. Now this may or may not help but consider moving form load code to the form shown event.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Hi Karen,

    When moving the creating text file and writing on it to form shown, I got the following error - Not Supported exception was unhandeled.

    And when I make the file name untitled even the code is written in Form Load or in Form Shown or in a Menu Strip, there was no problem and the file is created but last 15% of the content of text file are not completed.

    I add many empty lines to make last lines shown but still last lines not shown!!!!

    Then the problem is for that code line.

    file = My.Computer.FileSystem.OpenTextFileWriter("D:\" & My.Settings.FileName1 & ".txt", True)

    Kind Regards,


    Hany Metry


    • Edited by Hany Metry Wednesday, November 13, 2019 6:20 AM add
    Wednesday, November 13, 2019 5:15 AM
  • Hi

    Yes it does! The fault is that the owner needs to learn to debug.

    Here is YOUR code, only amended for testing purposes and this works fine, it will create the file if it doesn't exist, and it will append the lines if it does exist.

    Test this code and then scratch your head for a while before posting again.

    You will need to edit to suit your system - I just used the DeskTop for testing purposes.

    	Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    		Dim p As String = "C:\Users\lesha\Desktop\"
    		Dim MySettingsFilename1 As String = ""
    
    		Dim file As IO.StreamWriter
    		If MySettingsFilename1 = "" Then
    			file = My.Computer.FileSystem.OpenTextFileWriter(p & "Untitled.txt", True)
    		Else
    			file = My.Computer.FileSystem.OpenTextFileWriter(p & MySettingsFilename1 & ".txt", True)
    		End If
    		file.WriteLine("Line 1")
    		file.WriteLine("Line 2")
    		file.Close()
    	End Sub


    Regards Les, Livingston, Scotland

    Hi lashay,

    When I replace my code by the following code:

    Dim str60 As String = "D:\" & My.Settings.FileName1 & ".txt"
            If My.Settings.FileName1 = "" Then
                file = My.Computer.FileSystem.OpenTextFileWriter("D:\Untitled.txt", True)
            Else
                file = My.Computer.FileSystem.OpenTextFileWriter(str60, True)
            End If

    And the FileName1 has a name, then I got the error "Not Supported Exception was underhanded"

    At the following line code.

    file = My.Computer.FileSystem.OpenTextFileWriter(str60, True)

    Kind Regards,


    Hany Metry


    • Edited by Hany Metry Wednesday, November 13, 2019 7:15 AM adjust
    Wednesday, November 13, 2019 7:13 AM
  • Hi All,

    I guess that computer window does not know 'My.Settings.FileName1' and I guess that I need a file to be created by the my program to make computer window know My.Settings.FileName1 because I think that "My.Settings.FileName1" is go directly to computer window without transferred to string. If that is correct, that will be over my qualification and education and need professional one in computer window and visual studio.

    Kind regards,


    Hany Metry


    • Edited by Hany Metry Wednesday, November 13, 2019 8:30 AM add
    Wednesday, November 13, 2019 8:07 AM
  • Hi All,

    Can any one assist me for           Why text file is shown not completed till end.

    Is Note Pad show only limited lines or there are other problem?

    Kind Regards,


    Hany Metry

    Wednesday, November 13, 2019 8:56 AM
  • Hi All,

    I make the text file to be created from menu strip and I add the following code to delete existing file, if the user click menu strip two times.

    Dim str60 As String = "D:\" & My.Settings.FileName1 & ".txt"
            If My.Settings.FileName1 = "" Then
                If IO.File.Exists("D:\untitled.txt") Then My.Computer.FileSystem.DeleteFile("D:\untitled.txt")
            Else
                If IO.File.Exists(str60) Then My.Computer.FileSystem.DeleteFile(str60)
            End If
            If My.Settings.FileName1 = "" Then
                file = My.Computer.FileSystem.OpenTextFileWriter("D:\Untitled.txt", True)
            Else
                file = My.Computer.FileSystem.OpenTextFileWriter(str60, True)
            End If
            file.WriteLine(TV)
            file.WriteLine(str2007)

    It work good for untitled file name. 

    Kind Regards,


    Hany Metry

    Wednesday, November 13, 2019 9:52 AM
  • Hi,

    The following code does not create the text file and I don't know why.

    Dim file As System.IO.StreamWriter
                If My.Settings.FileName1 = "" Then
                    file = My.Computer.FileSystem.OpenTextFileWriter("D:\Untitled.txt", True)
                Else
                    file = My.Computer.FileSystem.OpenTextFileWriter("D:\" & My.Settings.FileName1 & ".txt", True)
                End If
                file.WriteLine(TV)
                file.WriteLine(Str2007)
                file.Close()

    Please advice

    Kind Regards,


    Hany Metry

    Hi,

    The strange thing is that I tested your code and the program works as expected. I have no way to reproduce your problem. I feel very sorry, maybe my ability is not enough.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 13, 2019 10:01 AM
    Moderator
  • Hi,

    The following code does not create the text file and I don't know why.

    Dim file As System.IO.StreamWriter
                If My.Settings.FileName1 = "" Then
                    file = My.Computer.FileSystem.OpenTextFileWriter("D:\Untitled.txt", True)
                Else
                    file = My.Computer.FileSystem.OpenTextFileWriter("D:\" & My.Settings.FileName1 & ".txt", True)
                End If
                file.WriteLine(TV)
                file.WriteLine(Str2007)
                file.Close()

    Please advice

    Kind Regards,


    Hany Metry

    Hi,

    The strange thing is that I tested your code and the program works as expected. I have no way to reproduce your problem. I feel very sorry, maybe my ability is not enough.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Hi Julie,

    The code does not work when I have specific name of the file while it work when the the file is untitled (that is with me)

    There is a solution of the problem by entering the file name with its extension and path in input data box but there will still problem of entering the extension wrong (not txt).

    I am working for that and I will write the code as soon as possible.

    Kind Regards, 


    Hany Metry


    • Edited by Hany Metry Wednesday, November 13, 2019 12:15 PM correction
    Wednesday, November 13, 2019 11:48 AM
  • Hi,

    Below is the code but it need improvement to make the default location and file name appear in input box as well as make massage box results if answer "OK" or answer "Cancel" and I still I can't read the last 7 lines of text file from note pad.

    I still need to read more in the input box.

    Dim file As System.IO.StreamWriter
            Dim str2007 As String
    44:     If My.Settings.FileName1 = "" Then
                str2007 = "File: Untitled.epcol"
            Else
                str2007 = "File: " & My.Settings.FileName1
            End If
            Dim str601 As String 
            Dim str60 As String
            str601 = InputBox("Choose Textfile Name and its Path", "D:\untitled", , , )
            str60 = str601
            If IO.File.Exists(str601 & ".txt") Then
                Dim msgRslt As MsgBoxResult = MsgBox("File is exist, replace it now?", (MsgBoxStyle.YesNo))
                If msgRslt = MsgBoxResult.Yes Then
                    My.Computer.FileSystem.DeleteFile(str60 & ".txt")
                    file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True)
                    'Else
                    file.WriteLine(TV)
                    file.WriteLine(str2007)
        
                Else
                    MsgBox("File not created", CType(MessageBoxButtons.OK, MsgBoxStyle))
                    GoTo 44
                End If
            Else
                file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True)
                file.WriteLine(TV)
                file.WriteLine(str2007)
                
            End If
        End Sub
    The problem that input box shape may be different from reference to an other because maybe it depend on visual studio year of issue.


    Hany Metry





    • Edited by Hany Metry Wednesday, November 13, 2019 3:19 PM as well as make massage box results if answer "OK" or answer "Cancel"
    Wednesday, November 13, 2019 1:21 PM
  • Hi

    Please replace the code you posted above with this and then when you run it, write down the Messagebox contents and post here.

    In case you get nerves, Yes, it is an instruction and if you do not like it, then just ignore it.#

    Dim file As System.IO.StreamWriter
            MessageBox.Show(My.Settings.FileName1)
            Dim str2007 As String
    44:     If My.Settings.FileName1 = "" Then
                str2007 = "File: Untitled.epcol"
            Else
                str2007 = "File: " & My.Settings.FileName1
            End If
            Dim str601 As String 
            Dim str60 As String
            str601 = InputBox("Choose Textfile Name and its Path", "D:\untitled", , , )
            str60 = str601
            If IO.File.Exists(str601 & ".txt") Then
                Dim msgRslt As MsgBoxResult = MsgBox("File is exist, replace it now?", (MsgBoxStyle.YesNo))
                If msgRslt = MsgBoxResult.Yes Then
                    My.Computer.FileSystem.DeleteFile(str60 & ".txt")
                    file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True)
                    'Else
                    file.WriteLine(TV)
                    file.WriteLine(str2007)
        
                Else
                    MsgBox("File not created", CType(MessageBoxButtons.OK, MsgBoxStyle))
                    GoTo 44
                End If
            Else
                file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True)
                file.WriteLine(TV)
                file.WriteLine(str2007)
                
            End If
        End Sub


    Regards Les, Livingston, Scotland


    • Edited by leshay Wednesday, November 13, 2019 1:35 PM
    • Marked as answer by Hany Metry Wednesday, November 13, 2019 3:39 PM
    • Unmarked as answer by Hany Metry Wednesday, November 13, 2019 3:47 PM
    Wednesday, November 13, 2019 1:33 PM
  • Hi,

    Please replace with this line.

    str601 = InputBox("Choose textfile Name and its Path without extension", "Textfile Name and its Path without extension", "D:\untitled", , )

    Concerning make massage box results if answer "OK" or answer "Cancel", I still need reference of how to refer to massage box results. 

    Concerning last 7 lines still not shown in the note Pad.

    Kind Regards,


    Hany Metry


    • Edited by Hany Metry Wednesday, November 13, 2019 3:22 PM Concerning make massage box results if answer "OK" or answer "Cancel", I still need reference of how to refer to massage box results.
    Wednesday, November 13, 2019 2:44 PM
  • Hi

    WHAT HAS AN INPUT BOX GOT TO DO WITH THIS THREAD?

    I for one have had enough of your wandering rants. You don't even know what your own question is - or if you do, you certainly don't know how to ask it.

    *

    I will not respond to any more of your so called questions - bye!


    Regards Les, Livingston, Scotland

    Wednesday, November 13, 2019 3:25 PM
  • Hi

    Please replace the code you posted above with this and then when you run it, write down the Messagebox contents and post here.

    In case you get nerves, Yes, it is an instruction and if you do not like it, then just ignore it.#

    Dim file As System.IO.StreamWriter
            MessageBox.Show(My.Settings.FileName1)
            Dim str2007 As String
    44:     If My.Settings.FileName1 = "" Then
                str2007 = "File: Untitled.epcol"
            Else
                str2007 = "File: " & My.Settings.FileName1
            End If
            Dim str601 As String 
            Dim str60 As String
            str601 = InputBox("Choose Textfile Name and its Path", "D:\untitled", , , )
            str60 = str601
            If IO.File.Exists(str601 & ".txt") Then
                Dim msgRslt As MsgBoxResult = MsgBox("File is exist, replace it now?", (MsgBoxStyle.YesNo))
                If msgRslt = MsgBoxResult.Yes Then
                    My.Computer.FileSystem.DeleteFile(str60 & ".txt")
                    file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True)
                    'Else
                    file.WriteLine(TV)
                    file.WriteLine(str2007)
        
                Else
                    MsgBox("File not created", CType(MessageBoxButtons.OK, MsgBoxStyle))
                    GoTo 44
                End If
            Else
                file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True)
                file.WriteLine(TV)
                file.WriteLine(str2007)
                
            End If
        End Sub


    Regards Les, Livingston, Scotland


    Hi Leshay,

    You will surprise from the results.

    The following code is incorrect.

    file = My.Computer.FileSystem.OpenTextFileWriter("D:\" & My.Settings.FileName1 & ".txt", True)

    Also the following code is incorrect because it contain extension epcol and we can not delete the extension.

    file = My.Computer.FileSystem.OpenTextFileWriter(My.Settings.FileName1 & ".txt", True)

    Kind Regards,

     

    Hany Metry



    • Marked as answer by Hany Metry Wednesday, November 13, 2019 3:38 PM
    • Unmarked as answer by Hany Metry Wednesday, November 13, 2019 3:47 PM
    • Edited by Hany Metry Wednesday, November 13, 2019 3:49 PM Also the following code is incorrect because it contain extension epcol and we can not delete the extension.
    Wednesday, November 13, 2019 3:33 PM
  • Hi,

    The following code is the correct code:

    Dim file As System.IO.StreamWriter
            Dim str2007 As String
    44:     If My.Settings.FileName1 = "" Then
                str2007 = "File: Untitled.epcol"
            Else
                str2007 = "File: " & My.Settings.FileName1
            End If
            Dim str601 As String
            Dim str60 As String
            str601 = InputBox("Choose textfile Name and its Path without extension", "Textfile Name and its Path without extension", "D:\untitled", , )
            str60 = str601
            If IO.File.Exists(str601 & ".txt") Then
                    Dim msgRslt As MsgBoxResult = MsgBox("File is exist, replace it now?", (MsgBoxStyle.YesNo))
                    If msgRslt = MsgBoxResult.Yes Then
                        My.Computer.FileSystem.DeleteFile(str60 & ".txt")
                        file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True)
                        'Else
                        file.WriteLine(TV)
                        file.WriteLine(str2007)
                    Else
                        MsgBox("File not created", CType(MessageBoxButtons.OK, MsgBoxStyle))
                        GoTo 44
                    End If
                Else
                    file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True)
                    file.WriteLine(TV)
                    file.WriteLine(str2007)
                End If
            End Sub
    The answer of Input Box by cancel means that the user is agree for the default name and path for the text file. 

    But still last 7 lines of text file not shown in the note pad but that is other problem not related to visual studio or visual basic and any how I will ask question in separate thread.


    Hany Metry



    • Marked as answer by Hany Metry Wednesday, November 13, 2019 4:14 PM
    • Unmarked as answer by Hany Metry Wednesday, November 13, 2019 4:18 PM
    • Marked as answer by Hany Metry Wednesday, November 13, 2019 4:28 PM
    • Edited by Hany Metry Wednesday, November 13, 2019 4:43 PM But still last 7 lines of text file not shown in the note pad but that is other problem not related to visual studio or visual basic and any how I will ask question in separate thread.
    Wednesday, November 13, 2019 4:13 PM
  • Hi

    Please replace the code you posted above with this and then when you run it, write down the Messagebox contents and post here.

    In case you get nerves, Yes, it is an instruction and if you do not like it, then just ignore it.#

    Dim file As System.IO.StreamWriter
            MessageBox.Show(My.Settings.FileName1)
            Dim str2007 As String
    44:     If My.Settings.FileName1 = "" Then
                str2007 = "File: Untitled.epcol"
            Else
                str2007 = "File: " & My.Settings.FileName1
            End If
            Dim str601 As String 
            Dim str60 As String
            str601 = InputBox("Choose Textfile Name and its Path", "D:\untitled", , , )
            str60 = str601
            If IO.File.Exists(str601 & ".txt") Then
                Dim msgRslt As MsgBoxResult = MsgBox("File is exist, replace it now?", (MsgBoxStyle.YesNo))
                If msgRslt = MsgBoxResult.Yes Then
                    My.Computer.FileSystem.DeleteFile(str60 & ".txt")
                    file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True)
                    'Else
                    file.WriteLine(TV)
                    file.WriteLine(str2007)
        
                Else
                    MsgBox("File not created", CType(MessageBoxButtons.OK, MsgBoxStyle))
                    GoTo 44
                End If
            Else
                file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True)
                file.WriteLine(TV)
                file.WriteLine(str2007)
                
            End If
        End Sub


    Regards Les, Livingston, Scotland


    Hi Leshay,

    You will surprise from the results.

    The following code is incorrect.

    file = My.Computer.FileSystem.OpenTextFileWriter("D:\" & My.Settings.FileName1 & ".txt", True)

    Also the following code is incorrect because it contain extension epcol and we can not delete the extension.

    file = My.Computer.FileSystem.OpenTextFileWriter(My.Settings.FileName1 & ".txt", True)

    Kind Regards,

     

    Hany Metry



    Hi Leshay,

    Really I was not know the answer of the massage box, because I was assume the answer is file name without extension and without file Path.

    If any one remember me that, maybe I was go to other way.

    Sorry Leshay, if you discover that late.

    Kind Regards,


    Hany Metry

    Wednesday, November 13, 2019 4:58 PM
    1. Hi
    2. WHAT HAS AN INPUT BOX GOT TO DO WITH THIS THREAD?
    3. I for one have had enough of your wandering rants. You don't even know what your own question is - or if you do, you certainly don't know how to ask it.
    4. *
    5. I will not respond to any more of your so called questions - bye!
    6. Regards Les, Livingston, Scotland

    Hi Leshay,

    Really I was not know the answer of the massage box, because I was assume the answer is file name without extension and without file Path.

    If any one remember me that, maybe I was go to other way.

    Sorry Leshay, if you discover that late.

    Kind Regards,



    Hany Metry

    Wednesday, November 13, 2019 5:00 PM
  • Hi

    WHAT HAS AN INPUT BOX GOT TO DO WITH THIS THREAD?

    I for one have had enough of your wandering rants. You don't even know what your own question is - or if you do, you certainly don't know how to ask it.

    *

    I will not respond to any more of your so called questions - bye!


    Regards Les, Livingston, Scotland

    Hi leshay,

    You have to know that, I have prepared first version of that program from 2016 and save properties, I have finished it from June 2016 and I do not remember every thing I have did from 2016, So I was not remember that FileName1 include extension and Path.

    Kind Regards,


    Hany Metry

    Wednesday, November 13, 2019 7:56 PM
  • Hi,

    The following code is the correct code:

    Dim file As System.IO.StreamWriter
            Dim str2007 As String
    44:     If My.Settings.FileName1 = "" Then
                str2007 = "File: Untitled.epcol"
            Else
                str2007 = "File: " & My.Settings.FileName1
            End If
            Dim str601 As String
            Dim str60 As String
            str601 = InputBox("Choose textfile Name and its Path without extension", "Textfile Name and its Path without extension", "D:\untitled", , )
            str60 = str601
            If IO.File.Exists(str601 & ".txt") Then
                    Dim msgRslt As MsgBoxResult = MsgBox("File is exist, replace it now?", (MsgBoxStyle.YesNo))
                    If msgRslt = MsgBoxResult.Yes Then
                        My.Computer.FileSystem.DeleteFile(str60 & ".txt")
                        file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True)
                        'Else
                        file.WriteLine(TV)
                        file.WriteLine(str2007)
                    Else
                        MsgBox("File not created", CType(MessageBoxButtons.OK, MsgBoxStyle))
                        GoTo 44
                    End If
                Else
                    file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True)
                    file.WriteLine(TV)
                    file.WriteLine(str2007)
                End If
            End Sub
    The answer of Input Box by cancel means that the user is agree for the default name and path for the text file. 

    But still last 7 lines of text file not shown in the note pad but that is other problem not related to visual studio or visual basic and any how I will ask question in separate thread.


    Hany Metry



    Hi All,

    I am thinking to have two input boxes, one for the file path and other one for file name to be sure that the user don't enter a wrong file path (that there will be massage box, if the file path not exist) but still there will be a problem if the user enter again file path with file name at the second input box? what will be the massage box? (may be I will have massage box of some characters should not be included in file name like /  :   ) 

    Maybe tomorrow, I will think enough for that point.

    Kind Regards,


    Hany Metry

    Wednesday, November 13, 2019 9:50 PM
  • Hi,

    The following code is the correct code:

    Dim file As System.IO.StreamWriter
            Dim str2007 As String
    44:     If My.Settings.FileName1 = "" Then
                str2007 = "File: Untitled.epcol"
            Else
                str2007 = "File: " & My.Settings.FileName1
            End If
            Dim str601 As String
            Dim str60 As String
            str601 = InputBox("Choose textfile Name and its Path without extension", "Textfile Name and its Path without extension", "D:\untitled", , )
            str60 = str601
            If IO.File.Exists(str601 & ".txt") Then
                    Dim msgRslt As MsgBoxResult = MsgBox("File is exist, replace it now?", (MsgBoxStyle.YesNo))
                    If msgRslt = MsgBoxResult.Yes Then
                        My.Computer.FileSystem.DeleteFile(str60 & ".txt")
                        file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True)
                        'Else
                        file.WriteLine(TV)
                        file.WriteLine(str2007)
                    Else
                        MsgBox("File not created", CType(MessageBoxButtons.OK, MsgBoxStyle))
                        GoTo 44
                    End If
                Else
                    file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True)
                    file.WriteLine(TV)
                    file.WriteLine(str2007)
                End If
            End Sub
    The answer of Input Box by cancel means that the user is agree for the default name and path for the text file. 

    But still last 7 lines of text file not shown in the note pad but that is other problem not related to visual studio or visual basic and any how I will ask question in separate thread.


    Hany Metry



    Hi All,

    I am thinking to have two input boxes, one for the file path and other one for file name to be sure that the user don't enter a wrong file path (that there will be massage box, if the file path not exist) but still there will be a problem if the user enter again file path with file name at the second input box? what will be the massage box? (may be I will have massage box of some characters should not be included in file name like /  :   ) 

    Maybe tomorrow, I will think enough for that point.

    Kind Regards,


    Hany Metry

    Hi All,

    Maybe also instead of two input box, it will be one input box + Folder Browser Dialog.

    Kind Regards,


    Hany Metry

    • Marked as answer by Hany Metry Thursday, November 14, 2019 6:30 AM
    Wednesday, November 13, 2019 10:53 PM
  • Hi All,

    Below is not final code that I still have a small problem is how to prevent the character " to be chosen from file name.

    Dim file As System.IO.StreamWriter Dim str2007 As String 44: If My.Settings.FileName1 = "" Then str2007 = "File: Untitled.epcol" Else str2007 = "File: " & My.Settings.FileName1 End If TV = "Licensed to :Orascom Construction" Dim str601 As String Dim str601a As String Dim str60 As String Dim path As String Dim Letter As String FolderBrowserDialog1.ShowDialog() path = FolderBrowserDialog1.SelectedPath 45: str601a = InputBox("Choose textfile Name without Path and without extension", "Textfile Name without Path and without extension", "untitled", , )

    If str601a.Length > 25 Then
                MsgBox("Character length shall not exceed 25", CType(MessageBoxButtons.OK, MsgBoxStyle))
                GoTo 45
            End If

    For xf As Integer = 0 To str601a.Length - 1 Letter = str601a.Substring(xf, 1) If xf > 0 Then GoTo 46 If IsNumeric(str601a.Substring(0, 1)) Then MsgBox("First character must not be a Numeric", CType(MessageBoxButtons.OK, MsgBoxStyle)) GoTo 45 End If 46: If Letter.Contains(".") = True Or Letter.Contains("/") Or Letter.Contains("\") Or Letter.Contains("?") Or Letter.Contains("!") Or Letter.Contains("@") Or Letter.Contains("#") Or Letter.Contains("$") Or Letter.Contains("%") Or Letter.Contains("^") Or Letter.Contains("&") Or Letter.Contains("*") Or Letter.Contains("(") Or Letter.Contains(")") Or Letter.Contains("+") Or Letter.Contains("=") Or Letter.Contains("<") Or Letter.Contains(">") Or Letter.Contains(":") Or Letter.Contains("'") Or Letter.Contains("|") Or Letter.Contains("_") Or Letter.Contains("-") Or Letter.Contains("{") Or Letter.Contains("[") Or Letter.Contains("}") Or Letter.Contains("]") Or Letter.Contains(";") Or Letter.Contains(",") Or Letter.Contains("`") Or Letter.Contains("~") Or Letter.Contains(" ") Then MsgBox("Character is not allowed", CType(MessageBoxButtons.OK, MsgBoxStyle)) GoTo 45 End If Next str601 = path & str601a str60 = str601 If IO.File.Exists(str601 & ".txt") Then Dim msgRslt As MsgBoxResult = MsgBox("File is exist, replace it now?", (MsgBoxStyle.YesNo)) If msgRslt = MsgBoxResult.Yes Then My.Computer.FileSystem.DeleteFile(str60 & ".txt") file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True) 'Else file.WriteLine(TV) file.WriteLine(str2007) Else MsgBox("File not created", CType(MessageBoxButtons.OK, MsgBoxStyle)) GoTo 44 End If Else file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True) file.WriteLine(TV) file.WriteLine(str2007) End If


    Kind Regards,


    Hany Metry




    • Marked as answer by Hany Metry Thursday, November 14, 2019 6:30 AM
    • Edited by Hany Metry Thursday, November 14, 2019 7:30 AM Below is not final code that I still have a small problem is how to prevent the character " to be chosen from file name.
    Thursday, November 14, 2019 6:21 AM
  • Hi All,

    Below is not final code that I still have a small problem is how to prevent the character " to be chosen from file name.

    Dim file As System.IO.StreamWriter Dim str2007 As String 44: If My.Settings.FileName1 = "" Then str2007 = "File: Untitled.epcol" Else str2007 = "File: " & My.Settings.FileName1 End If TV = "Licensed to :Orascom Construction" Dim str601 As String Dim str601a As String Dim str60 As String Dim path As String Dim Letter As String FolderBrowserDialog1.ShowDialog() path = FolderBrowserDialog1.SelectedPath 45: str601a = InputBox("Choose textfile Name without Path and without extension", "Textfile Name without Path and without extension", "untitled", , )

    If str601a.Length > 25 Then
                MsgBox("Character length shall not exceed 25", CType(MessageBoxButtons.OK, MsgBoxStyle))
                GoTo 45
            End If

    For xf As Integer = 0 To str601a.Length - 1 Letter = str601a.Substring(xf, 1) If xf > 0 Then GoTo 46 If IsNumeric(str601a.Substring(0, 1)) Then MsgBox("First character must not be a Numeric", CType(MessageBoxButtons.OK, MsgBoxStyle)) GoTo 45 End If 46: If Letter.Contains(".") = True Or Letter.Contains("/") Or Letter.Contains("\") Or Letter.Contains("?") Or Letter.Contains("!") Or Letter.Contains("@") Or Letter.Contains("#") Or Letter.Contains("$") Or Letter.Contains("%") Or Letter.Contains("^") Or Letter.Contains("&") Or Letter.Contains("*") Or Letter.Contains("(") Or Letter.Contains(")") Or Letter.Contains("+") Or Letter.Contains("=") Or Letter.Contains("<") Or Letter.Contains(">") Or Letter.Contains(":") Or Letter.Contains("'") Or Letter.Contains("|") Or Letter.Contains("_") Or Letter.Contains("-") Or Letter.Contains("{") Or Letter.Contains("[") Or Letter.Contains("}") Or Letter.Contains("]") Or Letter.Contains(";") Or Letter.Contains(",") Or Letter.Contains("`") Or Letter.Contains("~") Or Letter.Contains(" ") Then MsgBox("Character is not allowed", CType(MessageBoxButtons.OK, MsgBoxStyle)) GoTo 45 End If Next str601 = path & str601a str60 = str601 If IO.File.Exists(str601 & ".txt") Then Dim msgRslt As MsgBoxResult = MsgBox("File is exist, replace it now?", (MsgBoxStyle.YesNo)) If msgRslt = MsgBoxResult.Yes Then My.Computer.FileSystem.DeleteFile(str60 & ".txt") file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True) 'Else file.WriteLine(TV) file.WriteLine(str2007) Else MsgBox("File not created", CType(MessageBoxButtons.OK, MsgBoxStyle)) GoTo 44 End If Else file = My.Computer.FileSystem.OpenTextFileWriter(str601 & ".txt", True) file.WriteLine(TV) file.WriteLine(str2007) End If


    Kind Regards,


    Hany Metry




    45:     str601a = InputBox("Choose textfile Name without Path and without extension", "Textfile Name without Path and without extension", "untitled", , )
            If str601a.Length > 25 Then
                MsgBox("Character length shall not exceed 25", CType(MessageBoxButtons.OK, MsgBoxStyle))
                GoTo 45
            End If
            For xf As Integer = 0 To str601a.Length - 1
                Letter = str601a.Substring(xf, 1)
                If xf > 0 Then GoTo 46
                If IsNumeric(str601a.Substring(0, 1)) Then
                    MsgBox("First character must not be a Numeric", CType(MessageBoxButtons.OK, MsgBoxStyle))
                    GoTo 45
                End If
    46:         If Letter.Contains(".") = True Or Letter.Contains("/") Or Letter.Contains("\") Or Letter.Contains("?") Or Letter.Contains("!") Or Letter.Contains("@") Or Letter.Contains("#") Or Letter.Contains("$") Or Letter.Contains("%") Or Letter.Contains("^") Or Letter.Contains("&") Or Letter.Contains("*") Or Letter.Contains("(") Or Letter.Contains(")") Or Letter.Contains("+") Or Letter.Contains("=") Or Letter.Contains("<") Or Letter.Contains(">") Or Letter.Contains(":") Or Letter.Contains("'") Or Letter.Contains("|") Or Letter.Contains("_") Or Letter.Contains("-") Or Letter.Contains("{") Or Letter.Contains("[") Or Letter.Contains("}") Or Letter.Contains("]") Or Letter.Contains(";") Or Letter.Contains(",") Or Letter.Contains("`") Or Letter.Contains("~") Or Letter.Contains(" ") Or Letter.Contains(Chr(34)) Then
                    MsgBox("Character is not allowed", CType(MessageBoxButtons.OK, MsgBoxStyle))
                    GoTo 45
                End If
            Next

    Hi All,

    That is the final code by replacing that part from the above post.

    to prevent double quote " the only way is to write       Or Letter.Contains(Chr(34))   that double quote code is 34 according to ASCII.

    Kind Regards,


    Hany Metry

    • Marked as answer by Hany Metry Thursday, November 14, 2019 12:29 PM
    Thursday, November 14, 2019 12:28 PM