Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
462 views
in Technique[技术] by (71.8m points)

vba - Receiving System.NotSupportedException when trying to make a string ProperCase (VB)

Private Sub btnNewStudent_Click(sender As Object, e As EventArgs) Handles btnNewStudent.Click
        Dim name As String = InputBox("Enter the Student's Name", "Name", "Student Name")
        name = StrConv(name, vbProperCase)
        addStudent(name)
        If name = "" Then
            errorMessage("Please Enter a Name")
            lstStudents.Items.Remove("")
        End If
End Sub

Error Description:

"System.NotSupportedException: No data is available for encoding 1252. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.

Error Details:

System.NotSupportedException HResult=0x80131515 Message=No data is available for encoding 1252. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method. Source=Microsoft.VisualBasic.Core StackTrace: at Microsoft.VisualBasic.Strings.StrConv(String str, VbStrConv Conversion, Int32 LocaleID) at StudentTrackerVB.frmStudentTrackers.btnNewStudent_Click(Object sender, EventArgs e) in E:CollegeYear 2Unit 15 - Object Oriented ProgrammingAssignment 3StudentTrackerVBStudentTrackerVBForm1.vb:line 11 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam)

When I try to make name into ProperCase, it comes up with an error. I've done a similar thing for items in an array making them UpperCase which works perfectly. But for some reason, this doesn't?

What am I doing wrong xD

question from:https://stackoverflow.com/questions/65919736/receiving-system-notsupportedexception-when-trying-to-make-a-string-propercase

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try using Globalization

    Dim ti As Globalization.TextInfo = Globalization.CultureInfo.CurrentCulture.TextInfo
    name = ti.ToTitleCase(name)

Changing Case


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...