如何使用FolderBrowsedialog将文本框数据保存到文件 [英] How to save textbox data to file using FolderBrowsedialog

查看:42
本文介绍了如何使用FolderBrowsedialog将文本框数据保存到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是VB.NET的新手。在我编译它的下面的代码中,当我检查选择 Radiobutton并浏览文件夹并clikc GENERATE HL7消息时出现错误,我收到错误< b>错误:表达式是一个值,因此不能成为作业的目标。当我检查默认 Radiobutton时,它就像一个魅力。但当我检查选择 Radiobutton时出现错误。我不知道我的代码中有什么问题。您可以在以下URL中找到我的设计: http://s1065.photobucket.com/user/ Izaz_Ahmed / media / Capture_zpst4jjgvxb.jpg.html



这是我的代码:



Am new to VB.NET. In the Below code when i compile it, Am getting an error when i check the Select Radiobutton and browse the folder and clikc the GENERATE HL7 Message am getting an error as "Error: Expression is a value and therefore cannot be the target of an assignment." when i check the Default Radiobutton it works like a charm. But when i check the Select Radiobutton am getting the error. I don't know whats wrong in my code. you can find my design in the following URL:http://s1065.photobucket.com/user/Izaz_Ahmed/media/Capture_zpst4jjgvxb.jpg.html

Here is my code:

Private Sub HL_Click(sender As Object, e As EventArgs) Handles HL.Click

        If vld(TxtProcode) = False Then
            Exit Sub
        End If

        Dim file As System.IO.StreamWriter
        Dim folderBrowser As New FolderBrowserDialog
        Dim fileDateTime As String = DateTime.Now.ToString("yyyyMMdd") & DateTime.Now.ToString("HHmmss") & ".HL7"
        Dim ts As String = DateTime.Now.ToString("yyyyMMdd") & DateTime.Now.ToString("HHmmss")
        'file = My.Computer.FileSystem.OpenTextFileWriter("C:\pdata\New folder\" & fileDateTime, True)
        folderBrowser.ShowNewFolderButton = True
        If RadioBtndefault.Checked Then
            TxtDob.Format = DateTimePickerFormat.Custom
            TxtDob.CustomFormat = "yyyyMMdd"
            TxtExamtime.Format = DateTimePickerFormat.Custom
            TxtExamtime.CustomFormat = "hhMMss"
            TxtExamdate.Format = DateTimePickerFormat.Custom
            TxtExamdate.CustomFormat = "yyyyMMdd"
            file = My.Computer.FileSystem.OpenTextFileWriter("C:\pdata\New folder\" & fileDateTime, True)
            file.WriteLine("MSH|^~\&|||||" & TxtExamdate.Text & "" & TxtExamtime.Text & "||ORM^O01||P|2.3.1")
            file.WriteLine("PID|||" & TxtId.Text & "||" & TxtFamilyname.Text & "^" & TxtGivenname.Text & "||" & TxtDob.Text & "||" & TxtGender.Text & "|||" & TxtStreet.Text & " " & TxtHouse.Text & "^^" & TxtCity.Text & "^^" & TxtPostcode.Text)
            file.WriteLine("PV1||O|||||||||||||||||" & TxtId.Text & "|||||||||||||||||||||||||" & ts)
            file.WriteLine("ORC|NW|" & ts & "|||||^^^S||" & TxtExamdate.Text)
            file.WriteLine("OBR||" & ts & "^" & ts & "||" & TxtProcode.Text & "|||" & TxtExamdate.Text & "" & TxtExamtime.Text & "|" & TxtExamdate.Text & "" & TxtExamtime.Text)
            file.WriteLine()
            file.Close()
        End If

        If RadioBtnselect.Checked Then
            If folderBrowser.ShowDialog() = DialogResult.OK Then
                file.WriteLine = folderBrowser.SelectedPath
                file.WriteLine("MSH|^~\&|||||" & TxtExamdate.Text & "" & TxtExamtime.Text & "||ORM^O01||P|2.3.1")
                file.WriteLine("PID|||" & TxtId.Text & "||" & TxtFamilyname.Text & "^" & TxtGivenname.Text & "||" & TxtDob.Text & "||" & TxtGender.Text & "|||" & TxtStreet.Text & " " & TxtHouse.Text & "^^" & TxtCity.Text & "^^" & TxtPostcode.Text)
                file.WriteLine("PV1||O|||||||||||||||||" & TxtId.Text & "|||||||||||||||||||||||||" & ts)
                file.WriteLine("ORC|NW|" & ts & "|||||^^^S||" & TxtExamdate.Text)
                file.WriteLine("OBR||" & ts & "^" & ts & "||" & TxtProcode.Text & "|||" & TxtExamdate.Text & "" & TxtExamtime.Text & "|" & TxtExamdate.Text & "" & TxtExamtime.Text)
                file.WriteLine()
                file.Close()
                Dim root As Environment.SpecialFolder = folderBrowser.RootFolder
            End If
        End If
End Class

推荐答案

设置写入文件的代码行:

The line of code that sets up writing to the file:
file = My.Computer.FileSystem.OpenTextFileWriter("C:\pdata\New folder\" & fileDateTime, True)





在d的If语句中电子按钮。使用其他按钮时,永远不会触发此代码。您需要将其放在if块之外,或者将其复制到If块以用于其他按钮。



Is within the If statement for the default button. This code is never hit when you use the other button. You need this to be outside the if block, or copied into the If block for the other button.


这篇关于如何使用FolderBrowsedialog将文本框数据保存到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆