Bogart gFunction.vb
Module gFunction
'其它不是常用的方法及函數 #Region " 將指定的數據格式轉換為英文格式" Public Function EnglishFormat(ByVal intNum As Double, ByVal blnMoney As Boolean) As String
On Error GoTo err
Dim strNum As String
Dim intStart As Integer
Dim strInt As String '整數位
Dim strDec As String '小數位 strNum = Trim(Str(System.Math.Round(intNum, )))
intStart = InStr(, strNum, ".")
If intStart > Then
'取出數據中的整數部分
strInt = Mid(strNum, , intStart - )
'取出數據中的小數部分
strDec = Mid(strNum, intStart + )
Else
'表如沒有小數位數
strInt = strNum
strDec = ""
End If
If blnMoney = True Then
EnglishFormat = JoinNum(strInt) & readDec1(strDec)
Else
EnglishFormat = JoinNum(strInt) & IIf(JoinNum(strInt) = "", Mid(readDec2(strDec), ), readDec2(strDec)) & " ONLY"
End If
Exit Function
err:
EnglishFormat = "ZERO"
End Function '數字轉為英文字符
Private Function changeNumber(ByVal intI As String) As String
Select Case Int(intI)
Case
changeNumber = "ZERO"
Case
changeNumber = "ONE"
Case
changeNumber = "TWO"
Case
changeNumber = "THREE"
Case
changeNumber = "FOUR"
Case
changeNumber = "FIVE"
Case
changeNumber = "SIX"
Case
changeNumber = "SEVEN"
Case
changeNumber = "EIGHT"
Case
changeNumber = "NINE"
Case
changeNumber = "TEN"
Case
changeNumber = "ELEVEN"
Case
changeNumber = "TWELVE"
Case
changeNumber = "THIRTEEN"
Case
changeNumber = "FOURTEEN"
Case
changeNumber = "FIFTEEN"
Case
changeNumber = "SIXTEEN"
Case
changeNumber = "SEVENTEEN"
Case
changeNumber = "EIGHTEEN"
Case
changeNumber = "NINETEEN"
Case
changeNumber = "TWENTY"
Case
changeNumber = "THIRTY"
Case
changeNumber = "FORTY"
Case
changeNumber = "FIFTY"
Case
changeNumber = "SIXTY"
Case
changeNumber = "SEVENTY"
Case
changeNumber = "EIGHTY"
Case
changeNumber = "NINETY"
Case
changeNumber = "HUNDRED"
End Select
End Function 'N1 讀取小數部分(普通數據格式)
Private Function readDec1(ByVal intInt As String) As String
On Error Resume Next
Dim intlen As Integer
Dim strNum As String
Dim intN As String
intlen = Len(intInt)
Dim i As Integer
If intlen = Then Exit Function
For i = To intlen
'從右至左分別將每個數字轉為英文
intN = Mid(intInt, intlen + - i, )
strNum = changeNumber(intN) & " " & strNum
Next i
'如小數部分存在則在前加上'point'
If strNum = "" Then
Return strNum
Else
Return " POINT " & strNum
End If
End Function 'N2讀取小數部分(貨幣格式)
Private Function readDec2(ByVal intInt As String) As String
On Error Resume Next Dim intlen As Integer
Dim strNum As String
Dim intG As String
Dim i As Integer
If Len(intInt) = Then
Exit Function
ElseIf Len(intInt) = Then
intInt = intInt & ""
End If
Dim intN As String
intlen = Len(intInt)
For i = To intlen
'從右至左分別將每個數字轉為英文
intN = Mid(intInt, intlen + - i, )
Select Case i
Case '個位數
If intN > Then
strNum = changeNumber(intN)
Else
strNum = ""
End If
intG = intN
Case '十位數
If intN > Then
If intN < Then
strNum = changeNumber(intN & intG)
Else
If strNum <> "" Then
strNum = changeNumber(intN & "") & "-" & strNum
Else
strNum = changeNumber(intN & "")
End If
End If
End If
End Select
Next i
If strNum = "" Then
Return strNum
Else
Return " AND " & strNum & " CENTS"
End If End Function '取給定數據的個位,十和百位
'返回的值為 n thousand
Private Function read123(ByVal intInt As String) As String
Dim intlen As Integer
Dim strNum As String
intlen = Len(intInt)
Dim i As Integer
Dim intN As String
Dim intG As String
For i = To intlen
intN = Mid(intInt, intlen + - i, )
Select Case i
Case '個位數
If intN > Then
strNum = changeNumber(intN)
Else
strNum = ""
End If
intG = intN
Case '十位數
If intN > Then
If intN < Then '因為英文數字1到19無規則
strNum = changeNumber(intN & intG)
Else
If strNum <> "" Then
strNum = changeNumber(intN & "") & "-" & strNum
Else
strNum = changeNumber(intN & "")
End If
End If
End If
Case '百位數
If intN > Then
strNum = changeNumber(intN) & " HUNDRED " & strNum
End If
End Select
Next i
read123 = strNum
End Function '取給定數據的千位,十千和百千位
'返回的值為 n thousand Private Function read456(ByVal intInt As String) As String
Dim intlen As Integer
Dim strNum As String
intlen = Len(intInt)
Dim i As Integer
Dim intN As String
Dim intG As String
For i = To intlen
intN = Mid(intInt, intlen + - i, )
Select Case i
Case '個位數
If intN > Then
strNum = changeNumber(intN)
Else
strNum = ""
End If
intG = intN
Case '十位數
If intN > Then
If intN < Then
strNum = changeNumber(intN & intG)
Else
If strNum <> "" Then
strNum = changeNumber(intN & "") & "-" & strNum
Else
strNum = changeNumber(intN & "")
End If
End If
End If
Case '百位數
If intN > Then
strNum = changeNumber(intN) & " HUNDRED " & strNum
End If
End Select
Next i
If strNum = "" Then
read456 = ""
Else
read456 = strNum & " THOUSAND "
End If
End Function '取給定數據中的一個百萬位,十個百萬位和千個百萬位
'返回的值為 n million
Private Function read789(ByVal intInt As String) As String
Dim intlen As Integer
Dim strNum As String
intlen = Len(intInt)
Dim i As Integer
Dim intN As String
Dim intG As String '存儲臨時的數據
For i = To intlen
intN = Mid(intInt, intlen + - i, )
Select Case i
Case '個位數
'表示個位數在不為0時
If intN > Then
strNum = changeNumber(intN)
Else
strNum = ""
End If
intG = intN
Case '十位數
If intN > Then
If intN < Then '表十位數為1-19間
strNum = changeNumber(intN & intG)
Else
If strNum <> "" Then
strNum = changeNumber(intN & "") & "-" & strNum
Else
strNum = changeNumber(intN & "")
End If
End If
End If
Case '百位數
If intN > Then
strNum = changeNumber(intN) & " HUNDRED " & strNum
End If
End Select
Next i
If strNum = "" Then
read789 = ""
Else
read789 = strNum & "MILLION "
End If
End Function '合閾整數部分
Private Function JoinNum(ByVal strNum As String) As String
Dim str123 As String
Dim str456 As String
Dim str789 As String
str123 = read123(strNum)
str456 = read456(strNum)
str789 = read789(strNum) If str123 <> "" And str456 <> "" Then
str456 = read456(strNum) & "AND "
End If
If str456 <> "" And str789 <> "" Then
str789 = read789(strNum) & "AND "
End If
Return (str789 & str456 & str123).Trim End Function Private Function getValidChars(ByVal strSRC As String) As String
Dim i As Integer = strSRC.IndexOf(" ")
If i > Then
Return ((strSRC & "********").Substring(, i) & "******").Substring(, ) & "~1"
Else
Return strSRC
End If
End Function
#End Region #Region " 單位轉換函數"
'單位轉換函數,返回值為轉換系數,如無法轉換則返回-1
' Example: uomconv('CM','M') = 0.01
' Usage: uomconv(fm_uom,to_uom) Public Overloads Function uomconv(ByVal var1 As String, ByVal var2 As String) As Double
If var1 = var2 Then Return
Dim var3 As Double = -
Dim rst As ADODB.Recordset
Dim m As Integer
Dim ds As New DataSet Dim da As New OleDb.OleDbDataAdapter("select frunm,tounm,mltdiv,unmcvt from pcfunmb", netConn)
da.Fill(ds)
Dim dv As New DataView(ds.Tables(), "", "frunm,tounm,mltdiv", DataViewRowState.CurrentRows)
'dv.Sort = "frunm,tounm,mltdiv"
Dim var() As Object Try
var() = var1
var() = var2
var() =
m = dv.Find(var)
If m > Then
var3 = dv(m).Item("unmcvt")
Else
var() =
m = dv.Find(var)
If m > Then
var3 = / dv(m).Item("unmcvt")
Else
var() = var2
var() = var1
var() =
m = dv.Find(var)
If m > Then
var3 = / dv(m).Item("unmcvt")
Else
var() =
m = dv.Find(var)
If m > Then
var3 = dv(m).Item("unmcvt")
End If
End If
End If
End If
dv = Nothing
ds = Nothing
Return var3 Catch ex As Exception
Return -
End Try 'Try
' rst = New ADODB.Recordset
' rst.Open("select unmcvt from pcfunmb where frunm='" + var1 + "' and tounm='" + var2 + "' and mltdiv=1 order by unmcvt", adoConn)
' If rst.RecordCount > 0 Then
' For m = 0 To rst.RecordCount - 1
' var3 = rst.Fields("unmcvt").Value
' rst.MoveNext()
' Next
' Else
' rst = Nothing
' rst = New ADODB.Recordset
' rst.Open("select 1/unmcvt as unmcvt from pcfunmb where frunm='" + var1 + "' and tounm='" + var2 + "' and mltdiv = 2 order by unmcvt", adoConn)
' If rst.RecordCount > 0 Then
' For m = 0 To rst.RecordCount - 1
' var3 = rst.Fields("unmcvt").Value
' rst.MoveNext()
' Next
' Else
' rst = Nothing
' rst = New ADODB.Recordset
' rst.Open("select 1/unmcvt as unmcvt from pcfunmb where frunm='" + var2 + "' and tounm='" + var1 + "' and mltdiv = 1 order by unmcvt", adoConn)
' If rst.RecordCount > 0 Then
' For m = 0 To rst.RecordCount - 1
' var3 = rst.Fields("unmcvt").Value
' rst.MoveNext()
' Next
' Else
' rst = Nothing
' rst = New ADODB.Recordset
' rst.Open("select unmcvt as unmcvt from pcfunmb where frunm='" + var2 + "' and tounm='" + var1 + "' and mltdiv = 2 order by unmcvt", adoConn)
' If rst.RecordCount > 0 Then
' For m = 0 To rst.RecordCount - 1
' var3 = rst.Fields("unmcvt").Value
' rst.MoveNext()
' Next
' End If
' End If
' End If
' End If
' rst = Nothing
' Return var3
'Catch ex As Exception
' rst = Nothing
' Return -1
'End Try End Function '單位轉換函數,返回值為轉換系數,如無法轉換則返回-1
' Example2: uomconv('M','LB','CM','GSM') = 0.01
' Usage: uomconv(fm_uom,to_uom,std width,weight)
' M, LB/KG, CM, GSM Public Overloads Function uomconv(ByVal var1 As String, ByVal var2 As String, ByVal var3 As String, ByVal var4 As String) As Double
If var1 = var2 Then Return Dim v1, v2, v3, v4 As Double
v1 =
v2 =
v3 =
v4 = Dim rst As ADODB.Recordset
Dim m As Integer If var1 <> "M" Then
v1 = uomconv(var1, "M")
If v1 < Then Return -
End If If var2 <> "LB" Or var2 <> "KG" Then
v2 = uomconv(var2, "KG")
If v2 < Then
v2 = uomconv(var2, "LB")
If v2 < Then
Return -
Else
v2 = v2 * uomconv("LB", "KG") * uomconv("KG", "GM")
End If
Else
v2 = v2 * uomconv("KG", "GM")
End If
Else
If var2 = "LB" Then
v2 = uomconv("LB", "KG") * uomconv("KG", "GM")
ElseIf var2 = "KG" Then
v2 = uomconv("KG", "GM")
End If
End If
If v2 < Then Return - v3 = uomconv(var3, "M")
If v3 < Then Return - v4 = uomconv(var4, "GSM")
If v4 < Then Return -
Return (v1 * v3 * v4 / v2)
End Function Public Function GetInvQty(ByVal RMCode As String, ByVal Type As String, ByVal UOM As String, ByVal PurQty As Double, Optional ByVal DefaultValue As Double = ) As Double
Try
Dim InvUom As String = gData.selectValue(" select a.unm from phfrmt a where a.sug='" & Trim(Rmcode) & "'", adoConn)
Dim PurQty1 As Double = Val(PurQty)
If (Trim(UOM) = "LB" Or Trim(UOM) = "KG") And (InvUom <> "LB" And InvUom <> "KG") Then
Dim weight As Double = gData.selectValue("select WEIGHT from PHFRMTP where sug='" & Trim(Rmcode) & "' and ovy='" & Trim(Type) & "'", adoConn, ) Dim UOM1 As String = gData.selectValue("select WIDUNM from PHFRMTP where sug='" & Trim(Rmcode) & "' and ovy='" & Trim(Type) & "'", adoConn, ) Dim STDWID As Double = gData.selectValue("select STDWID from PHFRMTP where sug='" & Trim(Rmcode) & "' and ovy='" & Trim(Type) & "'", adoConn, ) If Trim(UOM) = "LB" Then
If UOM1 = "CM" Then
PurQty1 = * Val(PurQty1) / (Val(weight) * Val(STDWID))
Else
If UOM1 = "MM" Then
PurQty1 = * Val(PurQty1) / (Val(weight) * Val(STDWID))
Else
PurQty1 =
End If
End If
Else
If UOM1 = "CM" Then
PurQty1 = * Val(PurQty1) / (Val(weight) * Val(STDWID))
Else
If UOM1 = "MM" Then
PurQty1 = * Val(PurQty1) / (Val(weight) * Val(STDWID))
Else
PurQty1 =
End If
End If
End If
Else
Dim unmRate As Double = gData.selectValue("select unmcvt from pcfunmb where frunm='" & Trim(UOM) & "' and tounm='" & Trim(InvUom) & "'", adoConn, )
PurQty1 = PurQty1 * Val(unmRate)
End If Return Format(PurQty1, "0.0000")
Catch ex As Exception
Return DefaultValue
Exit Function
End Try
End Function Public Function GetPurQty(ByVal Sug As String, ByVal OVY As String, ByVal PurUnit As String, ByVal InvUnit As String, ByVal InvQty As Double) As Double
Dim PurQty1 As Double = Val(InvQty)
If PurUnit.Trim.ToUpper() = InvUnit.Trim.ToUpper() Then
Return Format(PurQty1, "0.000")
Exit Function
End If If (Trim(PurUnit) = "LB" Or Trim(PurUnit) = "KG") And (Trim(InvUnit) <> "LB" And Trim(InvUnit) <> "KG") Then
Dim weight As Double = CDbl(gData.SelectValue("select WEIGHT from PHFRMTP where sug='" & Trim(Sug) & "' and ovy='" & Trim(OVY) & "'", netConn, ""))
Dim UOM1 As String = gData.SelectValue("select WIDUNM from PHFRMTP where sug='" & Trim(Sug) & "' and ovy='" & Trim(OVY) & "'", netConn, "")
Dim STDWID As Double = CDbl(gData.SelectValue("select STDWID from PHFRMTP where sug='" & Trim(Sug) & "' and ovy='" & Trim(OVY) & "'", netConn, "")) If Trim(PurUnit) = "LB" Then
If UOM1 = "CM" Then
PurQty1 = (Val(PurQty1) * (Val(weight) * Val(STDWID))) /
Else
If UOM1 = "MM" Then
PurQty1 = (Val(PurQty1) * (Val(weight) * Val(STDWID))) /
Else
PurQty1 =
End If
End If
Else
If UOM1 = "CM" Then
PurQty1 = Val(PurQty1) * (Val(weight) * Val(STDWID)) * 0.00001
Else
If UOM1 = "MM" Then
PurQty1 = 0.000001 * Val(PurQty1) * (Val(weight) * Val(STDWID))
Else
PurQty1 =
End If
End If
End If
Else
Dim dt As DataTable = gData.GetDataTable("select FRUNM, TOUNM, UNMCVT, MLTDIV from PCFUNMB where FRUNM='" & InvUnit.Trim() & "' and TOUNM='" & PurUnit.Trim() & "'", netConn)
If dt.Rows.Count = Then
Dim rUnit As DataRow = dt.Rows()
If CStr(rUnit("MLTDIV")) = "" Then
PurQty1 = PurQty1 * rUnit("UNMCVT")
Else
If rUnit("UNMCVT") <> Then
PurQty1 = PurQty1 / rUnit("UNMCVT")
Else
PurQty1 =
End If
End If
Else
PurQty1 =
End If
End If
Return Format(PurQty1, "0.000")
End Function #End Region #Region "月份轉換,英文簡寫式"
Public Function MonthEnglishFormat(ByVal M As Int16) As String
Dim StrM As String
Select Case M
Case
StrM = "JAN"
Case
StrM = "FEB"
Case
StrM = "MAR"
Case
StrM = "APR"
Case
StrM = "MAY"
Case
StrM = "JUN"
Case
StrM = "JUL"
Case
StrM = "AUG"
Case
StrM = "SEP"
Case
StrM = "OCT"
Case
StrM = "NOV"
Case
StrM = "DEC"
Case Else
StrM = "ERROR"
End Select
Return StrM
End Function
#End Region End Module
Bogart gFunction.vb的更多相关文章
- Bogart BogartPublic.vb
Imports System.Data.SqlClient Imports System.Data #Region "IBogartToolbar,請勿隨便更改" Interfac ...
- Bogart SysPwd.vb
Module syspwd Public Const STR_MASK = "MyFunction" '加密用字串 '預定義密碼長度 Public GintCheckPwd As ...
- Bogart gSub.vb
'--------------Job No 0900408 -------------- '--DIM PART ONE ONLINE Update Order Qty '''主要新加過程名 Refr ...
- Bogart gData.vb
Imports System Imports System.Data Imports System.Data.OleDb Imports Microsoft.VisualBasic Imports S ...
- Bogart BogartAutoCode.vb
Imports System.Data.SqlClient Imports System.Data Public Class BogartAutoCodeDataBase Private Conn A ...
- Bogart gGrid.vb
Namespace BogartMis.Cls Public Class gGrid '設定表格控的列標題的別名 '說明:strItem字符串的格式為"01,02,03,04,05" ...
- [转载]C#中MessageBox.Show用法以及VB.NET中MsgBox用法
一.C#中MessageBox.Show用法 MessageBox.Show (String) 显示具有指定文本的消息框. 由 .NET Compact Framework 支持. MessageBo ...
- VB.NET设置控件和窗体的显示级别
前言:在用VB.NET开发射频检测系统ADS时,当激活已存在的目标MDI子窗体时,被其他子窗体遮住了,导致目标MDI子窗体不能显示. 这个问题怎么解决呢?网上看到一篇帖子VB.NET设置控件和窗体的显 ...
- 用VB脚本批到导入字段到PowerDesigner
在PowerDesigner使用脚本批量导入excel中记录的表结构信息,由于需要通过powerdesigner逆向工程创建一些sybase IQ的表,由于是接口数据,只有excel表,手动导入太耗时 ...
随机推荐
- Nim Game,一个有趣的游戏,也是一道入门算法题。
Nim Game,其实很多人都玩过.其实就是我们玩的划线游戏. 一张纸上,画若干条线,双方一人划一次,每次划掉1~3条线.可以选择画1条,也可以划2条,也可以3条.具体划去几条线完全看自己的策略.谁划 ...
- Navicat Premium连接PostgreSQL
连接PostgreSQL时,报错 大致意思:你当前的IP没有连接权限,在文件pg_hba中缺少当前IP的配置 解决:找你的PostgreSQL安装路径,这是我的:C:\Program Files\Po ...
- Linux操作系统网络配置
- Ubuntu Linux下的Wireshark使用drcom_2011.lua分析drcom协议
用文本编辑器打开init.lua配置文件,位置一般是//usr/share/wireshark/init.lua: sudo vim /usr/share/wireshark/init.lua 在in ...
- python 命名空间和作用域
这是python的难点和特点, 有很多的和c/cpp不一样的地方. 它的灵活易用性造成不习惯之处. refer to: http://blog.csdn.net/cc7756789w/article ...
- Maven的dependency type属性
官方地址: http://maven.apache.org/ref/3.5.2/maven-model/maven.html (搜索:Some examples are jar, war, ejb-c ...
- 声明变量(Declared Variable)和非声明变量(Undeclared Variable)的区别
声明变量的作用域限制在其声明位置的上下文中,而非声明变量总是全局的. 声明变量在任何代码执行前创建,而非声明变量只有在执行赋值操作的时候才会被创建. 声明变量是它所在上下文环境的不可配置属性(non- ...
- Vuejs项目的Webpack2构建优化
最近在做的项目因为相对较大(打包有100多个chunk),在build构建的时候速度一直上不去,甚是烦恼.由于用的是vue-cli的webpack2模板,一开始并没有想着要对其进行优化,一直觉得是we ...
- BASIC-2_蓝桥杯_01字串
问题描述 对于长度为5位的一个01串,每一位都可能是0或1,一共有32种可能.它们的前几个是: 请按从小到大的顺序输出这32种01串. 输入格式 本试题没有输入. 输出格式 输出32行,按从小到大的顺 ...
- 【转载】webstorm-前端javascript开发神器中文教程和技巧分享
webstorm是一款前端javascript开发编辑的神器,此文介绍webstorm的中文教程和技巧分享. webstorm8.0.3中文汉化版下载:百度网盘下载:http://pan.baidu. ...