|
Компьютерный форум OSzone.net » Программирование, базы данных и автоматизация действий » Программирование и базы данных » Разное - VB.NET | Границы строки |
|
Разное - VB.NET | Границы строки
|
Ветеран Сообщения: 1404 |
VB.Net 2002
Надо currentposition < Len(s), НО НЕЛЬЗЯ. Почему? Public Class Form1 Inherits System.Windows.Forms.Form Dim s As String Dim i As Integer Dim currentposition As Integer = 0 Dim beginning As Integer Dim tempstring As String Dim Lb, Inf As New Label() Dim Tx, MltTx As TextBox Dim Bt As New Button() Dim hzSize, constvAlign, consthAlign As Integer, _ vAlign As Integer = 5, _ hAlign As Integer = 5, _ vertSize As Integer = 20 #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 266) Me.Name = "Form1" Me.Text = "Form1" End Sub #End Region Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load constvAlign = vAlign consthAlign = hAlign Tx = New TextBox() MltTx = New TextBox() hzSize = 90 With Lb .Size = New Size(hzSize, vertSize) .Location = New Point(hAlign, vAlign) .Text = "Длина" .TextAlign = ContentAlignment.MiddleCenter .ForeColor = Color.Red End With hAlign = hAlign + hzSize + 5 hzSize = 100 With Tx .Size = New Size(hzSize, vertSize) .Location = New Point(hAlign, vAlign) .Text = "Введите число" .ForeColor = Color.Blue End With hAlign = hAlign + hzSize + 5 hzSize = 80 With Bt .Size = New Size(hzSize, vertSize) .Location = New Point(hAlign, vAlign) .Text = "Вычислить" .ForeColor = Color.Red End With hAlign = 5 vAlign = vAlign + vertSize + 10 vertSize = 200 hzSize = 200 With MltTx .Size = New Size(hzSize, vertSize) .Location = New Point(hAlign, vAlign) .Text = "" .ForeColor = Color.Blue .Multiline = True End With Controls.Add(Lb) Controls.Add(Tx) Controls.Add(Bt) Controls.Add(MltTx) AddHandler Bt.Click, AddressOf bt_click AddHandler MltTx.TextChanged, AddressOf MltTx_TextChanged End Sub Private Sub bt_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim fg As Boolean = True s = Trim(MltTx.Text) tempstring = "" beginning = currentposition While fg = True tempstring = "" beginning = currentposition 'ПОЧЕМУ нельзя While s.Substring(currentposition, 1) <> ' (" " Or vbCrLf Or "." Or "," Or ":" Or ";") Then 'Надо currentposition < Len(s) НО НЕЛЬЗЯ. Почему? While currentposition < Len(s) - 1 And _ String.Compare(s.Substring(currentposition, 1), " ") <> 0 And _ String.Compare(s.Substring(currentposition, 2), vbCrLf) <> 0 And _ String.Compare(s.Substring(currentposition, 1), ".") <> 0 And _ String.Compare(s.Substring(currentposition, 1), ",") <> 0 And _ String.Compare(s.Substring(currentposition, 1), ";") <> 0 And _ String.Compare(s.Substring(currentposition, 1), ":") <> 0 tempstring = tempstring & s.Substring(currentposition, 1) currentposition = currentposition + 1 End While 'ТАК КАК НЕЛЬЗЯ currentposition < Len(s) If currentposition = Len(s) - 1 Then tempstring = tempstring & s.Substring(currentposition, 1) fg = False End If If currentposition < Len(s) - 1 Then If String.Compare(s.Substring(currentposition, 2), vbCrLf) = 0 Then currentposition = currentposition + 2 Else currentposition = currentposition + 1 End If Else fg = False Bt.Enabled = False End If If Len(tempstring) > 0 And Len(tempstring) < Val(Tx.Text) Then fg = False End While If (Len(tempstring) < Val(Tx.Text)) Then MltTx.SelectionStart = beginning MltTx.SelectionLength = Len(tempstring) MltTx.Select() End If End Sub Private Sub MltTx_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Bt.Enabled = True tempstring = "" currentposition = 0 End Sub End Class |
|
Отправлено: 11:38, 23-03-2008 |
Ветеран Сообщения: 1404
|
Профиль | Отправить PM | Цитировать Суть вот в чем
Предположим, есть строка "fgfgfg" s="fgfgfg" Элементы в строке считаются с 0. В скобках номера элементов: "f(0)g(1)f(2)g(3)f(4)g(5)" Итак длина этой строки len(s)=6 Я могу обращаться к 0-5 элементам. Показатель номера элемента в строке currentposition Если currentposition<-1 или currentposition>=len(s) это ошибка выхода за пределы строки. Почему компилятор выдает ошибку выхода за пределы, если я в условии цикла обращаюсь к последнему элементу, т.е currentposition = 5 при длине 6 В чем загвоздка? |
------- Последний раз редактировалось mrcnn, 23-03-2008 в 12:17. Отправлено: 12:02, 23-03-2008 | #2 |
Для отключения данного рекламного блока вам необходимо зарегистрироваться или войти с учетной записью социальной сети. Если же вы забыли свой пароль на форуме, то воспользуйтесь данной ссылкой для восстановления пароля. |
Ветеран Сообщения: 1404
|
Профиль | Отправить PM | Цитировать Вопрос снят. Тему можно удалить.
String.Compare(s.Substring(currentposition,2), vbCrLf) |
------- Отправлено: 12:25, 23-03-2008 | #3 |
![]() |
Участник сейчас на форуме |
![]() |
Участник вне форума |
![]() |
Автор темы |
![]() |
Сообщение прикреплено |
| |||||
Название темы | Автор | Информация о форуме | Ответов | Последнее сообщение | |
MySQL - Автозамена строки из другой строки - trigger? procedure ? | BugZZ | Программирование и базы данных | 0 | 18-09-2009 09:51 | |
VB.NET | Превращение строки в число и конверсия типов | mrcnn | Программирование и базы данных | 3 | 16-03-2007 11:40 | |
CSS границы | Вебмастеру | 5 | 02-09-2006 23:53 | ||
Границы для картинки | Rudy | Вебмастеру | 2 | 13-11-2005 16:32 | |
Как получить путь к файлу в виде строки на Visual Basic .NET | Igor Laptev | Программирование и базы данных | 1 | 14-10-2003 00:50 |
|