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

1
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:\College\Year 2\Unit 15 - Object Oriented Programming\Assignment 3\StudentTrackerVB\StudentTrackerVB\Form1.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

vba
vb.net
asked on Stack Overflow Jan 27, 2021 by Ash • edited Jan 27, 2021 by Ash

1 Answer

1

Try using Globalization

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

Changing Case

answered on Stack Overflow Jan 27, 2021 by dbasnett

User contributions licensed under CC BY-SA 3.0