Results 1 to 2 of 2

Thread: `replacing the value of 0 and 1 to t and f

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Posts
    1

    Exclamation `replacing the value of 0 and 1 to t and f

    this is the code wriiten in the form ..........
    Code:
    Private Sub cmdAdd_Click()
       
        If LenB(cboInputs) Then
            cboInputs.AddItem Chr(65 + cboInputs.ListCount) & ": " & cboInputs.Text
        End If
    
        
    
    End Sub
    
    Private Sub cmdClear_Click()
        cboInputs.Clear
        lstTruthTable.Clear
        txtOutput = vbNullString
    End Sub
    
    Private Sub cmdDraw_Click()
      Dim i As Integer
        Dim l As Long
            For i = cboInputs.ListCount - 1 To 0 Step -1
                Next
        
        lstTruthTable.Clear
        For l = 0 To (2 ^ cboInputs.ListCount) - 1
            lstTruthTable.AddItem DecToBinary(l, cboInputs.ListCount)
        Next
        
        
    End Sub
    this is the code of the module.....
    Code:
    Option Explicit
    
    Function TruthTableAND(Inputs() As Boolean, Outputs() As Integer) As Boolean
        Dim i As Integer
        Dim l As Long
        For i = 0 To UBound(Inputs)
            If Inputs(i) Then l = l + (2 ^ i)
        Next
        
        For i = 0 To UBound(Outputs)
            If Outputs(i) = l Then
                TruthTableAND = True
                Exit Function
            End If
        Next
    End Function
    
    'if a+b+c+d
    Function TruthTableOR(Inputs() As Boolean, Outputs() As Integer) As Boolean
    
    
    End Function
    
    
    Function DecToBinary(Dec As Long, Places As Integer) As String
        Dim d As Long
        Dim strResult As String
        Dim intPlaces As Integer
        
        d = Dec
        
        Do Until d = 0
            If d Mod 2 Then
                strResult = "1" & strResult
                d = (d - 1) / 2
            Else
                strResult = "0" & strResult
                d = d / 2
            End If
        Loop
        intPlaces = Places - Len(strResult)
        If intPlaces > 0 Then strResult = Replace(Space(intPlaces) & strResult, " ", 0)
        DecToBinary = strResult
        Debug.Print strResult
    End Function
    please help me replace the output to t and f plzzz..tnks in advnce..
    Last edited by si_the_geek; Aug 20th, 2008 at 08:05 AM. Reason: added code tags

  2. #2
    Hyperactive Member
    Join Date
    Jan 2006
    Location
    Pakistan
    Posts
    388

    Re: `replacing the value of 0 and 1 to t and f

    Before the last line Debug.Print add this code:
    Code:
    strResult = Replace$(strResult,"0","f")
    strResult = Replace$(strResult,"1","t")
    Debug.Print strResult

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width