Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共9 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:全局代码中的Public变量用代码修改

1楼
李小胖 发表于:2025/5/21 14:35:00
全局代码
Public 颜色变量变量A
在全局代码中用
Public  Sub FIXA()
    修改颜色全局变量A=B
  output.show(颜色变量变量是B)
End Sub
output.show(颜色变量变量是A)
用全局代码修改了全局颜色变量A 在 Sub 里面输出颜色是我修改的颜色B
但是离开了Sub输出 颜色变量还是A

原代码是这样的
Public  Sub fixColor(i As String, ByRef cl As Color)
[此贴子已经被作者于2025/5/21 14:37:21编辑过]
2楼
有点蓝 发表于:2025/5/21 15:02:00
上面的代码只是定义了一个过程,并没有调用,只有调用这个过程,才会执行里面的代码,全局变量的值才会改变
3楼
李小胖 发表于:2025/5/21 15:04:00
啊...我调用了啊..我都output 了
4楼
李小胖 发表于:2025/5/21 15:27:00
这里是全局代码:
Dim i As Integer = 0
For Each k As String In colorNames.Keys
    Output.Show(k & ":" & colorNames(k))
    If GetConfigValue(k , colorNames(k)) <> colorNames(k) Then
        output.Show(k & "颜色修改前是:" & colors(i).Name)
        '修改颜色Sub
        fixColor(GetConfigValue(k , colorNames(k)) ,colors(i))
        
        output.Show(k & "颜色修改后是:" & colors(i).Name)
        output.Show(i)
 End If
    i = i + 1
Next
截图是调试输出

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

   
[此贴子已经被作者于2025/5/21 15:28:05编辑过]
5楼
有点蓝 发表于:2025/5/21 16:09:00
fixColor完整代码发上来
6楼
李小胖 发表于:2025/5/21 16:34:00
Public  Sub fixColor(i As String, ByRef cl As Color)
If i.Contains(";") AndAlso  Char.IsDigit(i(0)) Then
    '传入文本包含":"和首个字符是数字
    '颜色文本是RGB值
    
    Dim rgbValues As String() = i.Split(";"c)
    Dim r As Integer = Integer.Parse(rgbValues(0).Trim())
    Dim g As Integer = Integer.Parse(rgbValues(1).Trim())
    Dim b As Integer = Integer.Parse(rgbValues(2).Trim())
    cl = Color.FromArgb(r, g, b)
    Output.Show(cl.Name)
Else
    ' 不是包含数字
    '颜色文本是英文单词类似Red 处理
    cl = Color.FromName(i)
    Output.Show(cl.Name)
    'Output.Show("fixColor颜色是 " & cl.Name, "颜色信息")
End If
End Sub
7楼
有点蓝 发表于:2025/5/21 16:53:00
colorNames、colors这些变量是怎么定义和赋值的?
8楼
李小胖 发表于:2025/5/21 17:03:00
Dim colors() As Color = {_日历标题_背景起}
Dim colorNames As New Dictionary(Of String, String)
'字典键颜色的全局变量名称,字典值颜色的英文单词
colorNames.Add("_日历标题_背景起", "SteelBlue")


Dim i As Integer = 0
For Each k As String In colorNames.Keys
    Output.Show(k & ":" & colorNames(k))
    If GetConfigValue(k , colorNames(k)) <> colorNames(k) Then
        output.Show(k & "颜色修改前是:" & colors(i).Name)
        '修改颜色Sub
        fixColor(GetConfigValue(k , colorNames(k)) ,colors(i))
        
        output.Show(k & "颜色修改后是:" & colors(i).Name)
        output.Show(i)
    End If
    i = i + 1
Next
9楼
有点蓝 发表于:2025/5/21 17:12:00
Color是结构体,不是类型,属于值类型,传入函数会变成复制的副本,使用ByRef 是没有用的,需要显示返回
全局代码
Public  function fixColor(i As String) as Color
dim cl As Color
If i.Contains(";") AndAlso  Char.IsDigit(i(0)) Then
    '传入文本包含":"和首个字符是数字
    '颜色文本是RGB值
    
    Dim rgbValues As String() = i.Split(";"c)
    Dim r As Integer = Integer.Parse(rgbValues(0).Trim())
    Dim g As Integer = Integer.Parse(rgbValues(1).Trim())
    Dim b As Integer = Integer.Parse(rgbValues(2).Trim())
    cl = Color.FromArgb(r, g, b)
    Output.Show(cl.Name)
Else
    ' 不是包含数字
    '颜色文本是英文单词类似Red 处理
    cl = Color.FromName(i)
    Output.Show(cl.Name)
    'Output.Show("fixColor颜色是 " & cl.Name, "颜色信息")
End If
return cl
End function 


调用
……
    If GetConfigValue(k , colorNames(k)) <> colorNames(k) Then
        output.Show(k & "颜色修改前是:" & colors(i).Name)
        '修改颜色Sub
        colors(i) = fixColor(GetConfigValue(k , colorNames(k)) )
        
        output.Show(k & "颜色修改后是:" & colors(i).Name)
        output.Show(i)
    End If
……
[此贴子已经被作者于2025/5/21 17:12:58编辑过]
共9 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .04492 s, 2 queries.