If Option1.Value = True Then
    If Option2.Value = False Then
       myRecord.Fields("SendTime").Value = Time_now.Text    '发送时间为当前时间
    End If
    End If
        If Option2.Value = True Then
    If Option1.Value = False Then
       myRecord.Fields("SendTime").Value = Time_scheduled.Text    '自定义发送时间
    End If
    End If
    
    
    If Option2.Value = True Then
    If CDate(Time_now.Text) > CDate(Time_scheduled.Text) Then
       MsgBox "时间输入有误,请重新输入!", vbExclamation, "注意"
       Time_scheduled.SetFocus
       Exit Sub
    End If
    End If
我在form中用了两个option按钮,来选择发送短信的时间,一个是当前时间,一个是自定义的时间,两个不能同时用。这段代码是不是有问题啊。
还有如何把这个功能写到modul中去,让别人用起来方便一些。我觉得那不是要有好几个参数吗?
对VB还不是很熟悉来做这个工作,真是死了很多脑细胞啊。唉。请大家帮帮忙。

解决方案 »

  1.   

    Time_scheduled是不能改动的,是吗?
      

  2.   

    '调用方式如下:
    'SendSMS (Time_now.Text) 发送时间为当前时间
    'SendSMS (Time_scheduled.Text) 自定义发送时间Public Function SendSMS(ByVal SendTime As String) As Long       If Option1.Value = True Then
              myRecord.Fields("SendTime").Value = SendTime 'Time_now.Text 发送时间为当前时间
              SendSMS = 1
           Else
              If CDate(Time_now.Text) > CDate(SendTime) Then '这个判断自己改一下,如果是午夜就出问题了
                 MsgBox "时间输入有误,请重新输入!", vbExclamation, "注意"
                 Time_scheduled.SetFocus
                  SendSMS = 0
                 Exit Function
              Else
                 myRecord.Fields("SendTime").Value = SendTime 'Time_scheduled.Text 自定义发送时间
                  SendSMS = 1
              End If
           End If
                 
    End Function
      

  3.   

    在Function里不应该还有Option1.Value 这样的语句了吧,因为是要写在modul里的,别人用的时候可能不用option1这个option按钮了啊,这个是不是也要做为一个参数呢,谢谢
      

  4.   

    是的,多加一个参数 byval vOption as OptionButton
    函数里对应换过来.
      

  5.   

    能不能不用optionbutton 做参数啊 用一个Boolean类型的作参数
      

  6.   

    还有myRecord.Fields("SendTime").Value ,Time_now.Text,这些怎么办呢,都要写成参数吗。天哪,我觉得是不是一开始编程的思想就不对。
      

  7.   

    Public Function SendSMS(ByVal SendTime As String,byval blnSelect1 as boolean,byval blnSelect2 as boolean) As Long       If blnSelect1 Then
      

  8.   

    这些
    Option1
    Option2
    myRecord.Fields("SendTime").Value
    Time_now.Text   
    Time_scheduled.Text 
    Time_scheduled.SetFocus 
      

  9.   

    Option1                           ……byval blnSelect1 as boolean
    Option2                           ……byval blnSelect1 as boolean
    Time_now.Text                     ……byval strTimeNow as string
    Time_scheduled.Text               ……byval strTimeScheduled as string
    myRecord.Fields("SendTime").Value ……如果函数内使用myRecord则不用,否则作为函数返回值 
    Time_scheduled.SetFocus           ……Time_scheduled as textbox
      

  10.   

    Function Timeoption(ByVal SendTime As String, ByVal myoption As Boolean, ByVal timetable As String, ByVal timenow As String) As Long    
        If myoption = True Then
              timetable = SendTime 'Time_now.Text 发送时间为当前时间
              
           Else
              If CDate(timenow) > CDate(SendTime) Then
                 MsgBox "时间输入有误,请重新输入!", vbExclamation, "注意"
                 'Time_scheduled.SetFocus
                  
                 Exit Function
              Else
                 timetable = SendTime 'Time_scheduled.Text 自定义发送时间
                  
              End If
           End IfEnd Function调用时这样:
    Call Timeoption(Text4.Text, Option1.Value, Text5.Text, timenow)可是不对啊,text5收不到东西  ,问题出在哪儿啊
      

  11.   

    Function Timeoption(ByVal SendTime As String, ByVal myoption As Boolean, ByVal timenow As String) As string     
        If myoption = True Then 
              timetable = SendTime 'Time_now.Text 发送时间为当前时间 
              
          Else 
              If CDate(timenow) > CDate(SendTime) Then 
                MsgBox "时间输入有误,请重新输入!", vbExclamation, "注意" 
                'Time_scheduled.SetFocus 
                  
                Exit Function 
              Else 
                timetable = SendTime 'Time_scheduled.Text 自定义发送时间 
                  
              End If 
          End If End Function  Text5.Text=Timeoption(Text4.Text, Option1.Value , timenow)
      

  12.   

    text5不要放在参数里,取函数返回值,ls有问题,修改一下Function Timeoption(ByVal SendTime As String, ByVal myoption As Boolean, ByVal timenow As String) As string 
         dim timetable as string
        
        If myoption = True Then 
              timetable = SendTime 'Time_now.Text 发送时间为当前时间 
              
          Else 
              If CDate(timenow) > CDate(SendTime) Then 
                MsgBox "时间输入有误,请重新输入!", vbExclamation, "注意" 
                'Time_scheduled.SetFocus 
                  
                Exit Function 
              Else 
                timetable = SendTime 'Time_scheduled.Text 自定义发送时间 
                  
              End If 
          End If       Timeoption=temetable
    End Function Text5.Text=Timeoption(Text4.Text, Option1.Value , timenow)
      

  13.   

    其实如果text5作为参数应该这样Function Timeoption(ByVal SendTime As String, ByVal myoption As Boolean,  timetable As textbox, ByVal timenow As String) As Long     
        If myoption = True Then 
              timetable = SendTime 'Time_now.Text 发送时间为当前时间 
              
          Else 
              If CDate(timenow) > CDate(SendTime) Then 
                MsgBox "时间输入有误,请重新输入!", vbExclamation, "注意" 
                'Time_scheduled.SetFocus 
                  
                Exit Function 
              Else 
                timetable = SendTime 'Time_scheduled.Text 自定义发送时间 
                  
              End If 
          End If End Function 
    调用时这样: 
    Call Timeoption(Text4.Text, Option1.Value, Text5.Text, timenow)