Guest User

Untitled

a guest
Jul 4th, 2012
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. Compiler Error Message: CS1026: ) expected - C# .Net, fine in VB .Net
  2. <%@ Page Language="C#" %>
  3. <script runat="server">
  4. Sub btnConvert_Click(sender As Object, e As EventArgs)
  5. Try
  6. lblToInt1.Text = cint(txtValue1.Text)
  7. Catch
  8. lblToInt1.Text = "Could not convert to Integer"
  9.  
  10. End Try
  11.  
  12. Try
  13. lblToInt2.Text = cint(txtValue2.Text)
  14. Catch
  15. lblToInt2.Text = "Could not convert to Integer"
  16.  
  17. End Try
  18. lblToInt3.Text = cint(txtValue1.Text)+cint(txtValue2.Text)
  19. End Sub
  20.  
  21. </script>
  22. <html>
  23. <head>
  24. </head>
  25. <body>
  26. <form runat="server">
  27. <p>
  28. Text Value 1:
  29. <asp:TextBox id="txtValue1" runat="server"></asp:TextBox>
  30. </p>
  31. <p>
  32. Text Value 2:
  33. <asp:TextBox id="txtValue2" runat="server"></asp:TextBox>
  34. &nbsp;<asp:Button id="btnConvert" onclick="btnConvert_Click" runat="server" Text="Do it!"></asp:Button>
  35. </p>
  36. <p>
  37. Convert to Integer produces 1:
  38. <asp:Label id="lblToInt1" runat="server"></asp:Label>
  39. </p>
  40. <p>
  41. Convert to Integer produces 2:
  42. <asp:Label id="lblToInt2" runat="server"></asp:Label>
  43. </p>
  44. <p>
  45. Total of your 2 numbers:
  46. <asp:Textbox id="lblToInt3" runat="server"></asp:Textbox>
  47. </p>
  48. </form>
  49. </body>
  50. </html>
  51.  
  52. void btnConvert_Click(object sender, EventArgs e)
  53. {
  54. try
  55. {
  56. lblToInt1.Text = int.Parse(txtValue1.Text).ToString();
  57. }
  58. catch //this could be replaced by a single call to int.TryParse
  59. {
  60. lblToInt1.Text = "Could not convert to Integer";
  61. }
  62. // etc, etc...
  63. }
Advertisement
Add Comment
Please, Sign In to add comment