以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  判断字符串是否包含星号,如果有星号则进行分割填充,代码怎么写?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=146420)

--  作者:yacity
--  发布时间:2020/2/23 17:33:00
--  判断字符串是否包含星号,如果有星号则进行分割填充,代码怎么写?



如图,当规格包含* 比如20*0.05  那么自动分割和填充 宽度等于20 厚度等于0.05


        如果含有多个只取前面两部分 比如100*0.03*15公斤 那么宽度=100 厚度=0.03


        如果规格不含* 则不填充宽度和厚度。


      代码怎么写啊?


      当规格等于80*100=33G 类似这样的时候会出错,怎么解决?


 



此主题相关图片如下:未标题-2.jpg
按此在新窗口浏览图片



Dim tbl As Table = Tables("吹膜选产品_Table1")
If tbl.Current IsNot Nothing Then



    Tables("chuimo").Current("chanpinid") = tbl.Current("chanpinid")


\'分割规格,分别自动填入 宽度 厚度
Dim guige1=tbl.current("guige")
If guige1="" Or guige1.IndexOf("*") = -1 Then
Tables("chuimo").current("kuandu")=""
 Tables("chuimo").current("houdu")=""
Else
Dim s1() As String
s1=guige1.split("*")
Tables("chuimo").current("kuandu")=s1(0)
Tables("chuimo").current("houdu")=s1(1)
End If



End If
Forms("
吹膜选产品").Close()


 


[此贴子已经被作者于2020/3/5 16:39:29编辑过]

--  作者:liufucan
--  发布时间:2020/2/23 18:20:00
--  
Tables("chuimo").current("houdu")=s1(1). split("=")(0)
--  作者:有点蓝
--  发布时间:2020/2/23 21:58:00
--  
Dim guige1  as string = tbl.current("guige")
Dim sps() As Char = {"*","="}
dim s1() As String=guige1.split(sps)
if s1.length > 1 then
Tables("chuimo").current("kuandu")=s1(0)
Tables("chuimo").current("houdu")=s1(1)
else
Tables("chuimo").current("kuandu")=""
 Tables("chuimo").current("houdu")=""
end if
[此贴子已经被作者于2020/2/23 21:59:16编辑过]

--  作者:yacity
--  发布时间:2020/3/5 11:32:00
--  
还是会出错,当选择产品名称 一级红双草绳  规格 8CM 类似这样的格式 会出现以下错误提示:

图片点击可在新窗口打开查看此主题相关图片如下:6.jpg
图片点击可在新窗口打开查看

代码如下:
-----------------------------------------------------------------

吹膜选产品_TextBox1_TextChanged

 

Dim txt As String = e.Form.Controls("TextBox1").Text

Dim tbl As Table = Tables("吹膜选产品_Table1")

tbl.Filter= ""

If txt = "" Then

    tbl.Filter = ""

Else

   txt = "\'*" & txt.Replace("*","[*]") & "*\'"

    \'或者 txt = "\'*" & strtowide(txt) & "*\'"

 

If txt.IndexOf(" ") = -1 Then \'如果没有空格

tbl.filter = "chanpinname Like " & txt & " or guige Like " & txt & " or JM Like " & txt & " "

    tbl.Sort = "chanpinname desc,guige desc,danwei desc"

 

Else

\'Dim txt As String

Dim txt2 As String

Dim txt3 As String

Dim Values() As String

Values = txt.split(" ")

txt2=values(0)& "*\'"

txt3="\'*"& values(1)

 

    tbl.filter = "chanpinname Like " & txt2 & " And guige Like " & txt3 & " "

    tbl.Sort = "chanpinname desc,guige desc,danwei desc"

\'Messagebox.show(tbl.filter)

End If

End If





--  作者:yacity
--  发布时间:2020/3/5 11:33:00
--  
-------------------------------------------------------------------

吹膜选产品_TextBox1_KeyDown

 

Dim tbl As Table = Tables("吹膜选产品_Table1")

If e.KeyCode = Keys.Up Then

    tbl.Position = tbl.Position - 1

    e.Cancel = True

ElseIf e.KeyCode = Keys.Down Then

    tbl.Position = tbl.Position + 1

    e.Cancel = True

ElseIf e.KeyCode = Keys.Enter Then

    If tbl.Current IsNot Nothing Then

       \' Tables("chuimo").Current("chanpinname") = tbl.Current("chanpinname")

       \' Tables("chuimo").Current("guige") = tbl.Current("guige")

        \'Tables("chuimo").Current("danwei") = tbl.Current("danwei")

        Tables("chuimo").Current("chanpinid") = tbl.Current("chanpinid")

        Tables("chuimo").Current("addtime")= now()

        Tables("chuimo").Current("adduser")= user.name

 

\'分割规格,分别自动填入 宽度 厚度

Dim guige1  As String = tbl.current("guige")

Dim sps() As Char = {"*","="}

Dim s1() As String=guige1.split(sps)

If s1.length > 1 Then

Tables("chuimo").current("kuandu")=s1(0)

Tables("chuimo").current("houdu")=s1(1)

Else

Tables("chuimo").current("kuandu")=""

 Tables("chuimo").current("houdu")=""

End If

       

    End If

    e.Cancel = True

    e.Form.Close()

End If



--  作者:yacity
--  发布时间:2020/3/5 11:33:00
--  
-------------------------------------------------------------------------

吹膜选产品_Table1_DoubleClick

 

Dim tbl As Table = Tables("吹膜选产品_Table1")

If tbl.Current IsNot Nothing Then

 

  

    Tables("chuimo").Current("chanpinid") = tbl.Current("chanpinid")

    Tables("chuimo").Current("addtime")= now()

    Tables("chuimo").Current("adduser")= user.name

 

\'分割规格,分别自动填入 宽度 厚度

Dim guige1  As String = tbl.current("guige")

Dim sps() As Char = {"*","="}

Dim s1() As String=guige1.split(sps)

If s1.length > 1 Then

Tables("chuimo").current("kuandu")=s1(0)

Tables("chuimo").current("houdu")=s1(1)

Else

Tables("chuimo").current("kuandu")=""

 Tables("chuimo").current("houdu")=""

End If

End If

Forms("吹膜选产品").Close()


----------------------------------------------------------------------


--  作者:yacity
--  发布时间:2020/3/5 11:33:00
--  

吹膜选产品_Table1_KeyDown

 

If e.KeyCode = Keys.Enter Then

    Dim tbl As Table = Tables("吹膜选产品_table1")

    If tbl.Current IsNot Nothing Then

        \'Tables("chuimo").Current("chanpinname") = tbl.Current("chanpinname")

    \'Tables("chuimo").Current("guige") = tbl.Current("guige")

    \'Tables("chuimo").Current("danwei") = tbl.Current("danwei")

    Tables("chuimo").Current("chanpinid") = tbl.Current("chanpinid")

    Tables("chuimo").Current("addtime")= now()

    Tables("chuimo").Current("adduser")= user.name

 

\'分割规格,分别自动填入 宽度 厚度

Dim guige1  As String = tbl.current("guige")

Dim sps() As Char = {"*","="}

Dim s1() As String=guige1.split(sps)

If s1.length > 1 Then

Tables("chuimo").current("kuandu")=s1(0)

Tables("chuimo").current("houdu")=s1(1)

Else

Tables("chuimo").current("kuandu")=""

 Tables("chuimo").current("houdu")=""

End If

 

 

    End If

    Forms("吹膜选产品").Close()

End If

 

----------------------------------------------------------------
请问如何解决?


--  作者:有点蓝
--  发布时间:2020/3/5 12:07:00
--  
勾选4楼图片里的出错窗口的“显示详细信息”,看是哪个事件的问题?
--  作者:yacity
--  发布时间:2020/3/5 16:43:00
--  
 有时候会一直报错 (就是运行这段代码的时候每次都报错。)。直到重启电脑,有时候会报错,有时候不会。

.NET Framework 版本:4.0.30319.42000
Foxtable 版本:2020.1.19.19
错误所在事件:窗口,吹膜选产品,TextBox1,KeyDown
详细错误信息:
从字符串“”到类型“Double”的转换无效。
输入字符串的格式不正确。

[此贴子已经被作者于2020/3/5 16:43:39编辑过]

--  作者:yacity
--  发布时间:2020/3/5 16:48:00
--  
.NET Framework 版本:4.0.30319.42000
Foxtable 版本:2020.1.19.19
错误所在事件:chanpin,KeyDown
详细错误信息:
从字符串“”到类型“Double”的转换无效。
输入字符串的格式不正确。