vb小程序

此篇博客介绍了使用Visual Basic for Applications (VBA) 编程实现的个性化的字符串生成过程,包括根据用户选择判断性别、身份及兴趣爱好,并将结果动态显示。通过实例展示了如何结合If语句和数组操作来定制输出。
摘要由CSDN通过智能技术生成

在这里插入图片描述
Private Sub Command1_Click()
Dim s As String
s = "我是 "

'判断性别
If Option1.Value = True Then
s = s + “男”
Else
s = s + “女”
End If

'判断身份
If Option3.Value = True Then
s = s + “学生”
Else
s = s + “教师”
End If

s = s + “,爱好:”

'判断爱好
If Check1.Value = 1 Then '1选择,0未选择
s = s + “体育、”
End If
If Check2.Value = 1 Then '1选择,0未选择
s = s + “电影、”
End If
If Check3.Value = 1 Then '1选择,0未选择
s = s + “摄影。”
End If
If Check1.Value = 0 And Check2.Value = 0 And Check3.Value = 0 Then
s = s + “无。”
Else
s = Left(s, Len(s) - 1) + “。” '右截函数,去掉最后一个,改成句号
End If

'设置结果

Text1.Text = s

End Sub

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Option Explicit '函数声明 Private Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, _ ByVal Y As Long) As Long Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, _ ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, _ ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, _ ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long Const RGN_OR = 2 Dim I As Integer, j, myint, linex As Integer Dim Fullr, myColor, crn As Long Dim Region, PicWidth, PicHeight As Long Dim mystart, mybool As Boolean Private Sub Form_Load() Dim hDC As Long Me.Width = Picture1.Width '设置窗体宽度等于图形宽度 Me.Height = Picture1.Height '设置窗体宽度等于图形宽度 Picture1.ScaleMode = vbPixels '设置Picture1度量单位为像素 Picture1.AutoRedraw = True '设置Picture1自动重绘有效 Picture1.AutoSize = True '设置Picture1自动调整大小 Picture1.BorderStyle = vbBSNone '设置Picture1的边框样式 Me.BorderStyle = vbBSNone '设置窗体的边框样式 hDC = Picture1.hDC mystart = True mybool = False I = 0 j = 0 PicWidth = Picture1.ScaleWidth PicHeight = Picture1.ScaleHeight linex = 0 myColor = GetPixel(hDC, 0, 0) '获取picture1指定像素的rgb值 For j = 0 To PicHeight - 1 For I = 0 To PicWidth - 1 If GetPixel(hDC, I, j) = myColor Or I = PicWidth Then '透明像素 If mybool Then mybool = False crn = CreateRectRgn(linex, j, I, j - 1) '创建矩形区域 If mystart Then Fullr = crn mystart = False Else CombineRgn Fullr, Fullr, crn, RGN_OR '合并区域 DeleteObject CreateRectRgn(linex, j, I, j - 1) '删除透明区域 End If End If Else '非透明像素 If Not mybool Then mybool = True linex = I End If End If Next Next Region = Fullr SetWindowRgn Me.hWnd, Region, True '设置窗体区域 myint = 0 End Sub Private Sub Timer1_Timer() '形成动画 Dim hDC As Long myint = myint + 1 If myint = 1 Then Set Picture1.Picture = LoadPicture(App.Path & "\sz3.bmp") If myint = 2 Then Set Picture1.Picture = LoadPicture(App.Path & "\sz4.bmp") If myint = 3 Then Set Picture1.Picture = LoadPicture(App.Path & "\sz5.bmp") If myint = 4 Then Set Picture1.Picture = LoadPicture(App.Path & "\sz6.bmp") If myint = 5 Then myint = 0 hDC = Picture1.hDC mystart = True mybool = False I = 0 j = 0 Me.Width = Picture1.Width Me.Height = Picture1.Height PicWidth = Picture1.ScaleWidth PicHeight = Picture1.ScaleHeight linex = 0 myColor = GetPixel(hDC, 0, 0) '获取picture1指定像素的rgb值 For j = 0 To PicHeight - 1 For I = 0 To PicWidth - 1 If GetPixel(hDC, I, j) = myColor Or I = PicWidth Then '透明像素 If mybool Then mybool = False crn = CreateRectRgn(linex, j, I, j - 1) '创建矩形区域 If mystart Then Fullr = crn mystart = False Else CombineRgn Fullr, Fullr, crn, RGN_OR '合并区域 DeleteObject CreateRectRgn(linex, j, I, j - 1) '删除透明区域 End If End If Else '非透明像素 If Not mybool Then mybool = True linex = I End If End If Next Next Region = Fullr SetWindowRgn Me.hWnd, Region, True '设置窗体区域 End Sub Private Sub Picture1_Click() End End Sub
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱写程序的小范

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值