CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Jul 2002
    Location
    Leeds
    Posts
    123

    Colour test for VB Code

    Ivor B Gun
    Don Kiddick
    Seymor Butts
    Amanda Hugnkiss
    I P Freely
    Mike Hunt

    Hrm so thats the colours then, right now for code:

    ' This function makes a string of a specified length containing the specified characters. This function avoides the need for loops
    Public Function MakeStringOf(ByVal p_strChar As String, ByVal p_lngCount As Long) As String
    Dim strReturn As String

    ' Check that the character is not blank and the length is greater than zero
    If (p_strChar = "") Or (p_lngCount <= 0) Then
    strReturn = ""
    Else
    ' Make a string of spaces of the required length
    strReturn = Space(p_lngCount)
    If (p_strChar <> " ") Then
    ' Replace the spaces in the string with the specified character
    strReturn = Replace(strReturn, " ", p_strChar)
    End If
    End If

    MakeStringOf = strReturn
    End Function



    That was a lot of effort to do the coloring.' Make a string of spaces of the required length
    Some people say 'The world is a very strange place'

    Compared to what?

  2. #2
    Join Date
    Jul 2002
    Location
    Leeds
    Posts
    123

    # and PHP test

    What does # do? Well lets see:

    Code:
    ' This function makes a string of a specified number of a specified character e.g.
    ' a string of five dots "....." etc.
    Public Function MakeStringOf(ByVal p_strChar As String, ByVal p_lngCount As Long) As String
       Dim strReturn As String
       
       ' Check that the input character is not a blank string
       ' and that the length is not less than 0
       If (p_strChar = "") Or (p_lngCount <= 0) Then
          strReturn = ""
       Else
          ' Make a string of spaces of the specified size
          strReturn = Space(p_lngCount)
          If (p_strChar <> " ") Then
             ' Replace all of the spaces with the specified character.
             strReturn = Replace(strReturn, " ", p_strChar)
          End If
       End If
       
       ' Return the new string.
       MakeStringOf = strReturn
    End Function
    What does PHP do? Lets see:

    PHP Code:
    ' This function makes a string of a specified number of a specified character e.g.
    a string of five dots "....." etc.
    Public Function 
    MakeStringOf(ByVal p_strChar As StringByVal p_lngCount As Long) As String
       Dim strReturn 
    As String
       
       
    ' Check that the input character is not a blank string
       ' 
    and that the length is not less than 0
       
    If (p_strChar "") Or (p_lngCount <= 0Then
          strReturn 
    ""
       
    Else
          
    ' Make a string of spaces of the specified size
          strReturn = Space(p_lngCount)
          If (p_strChar <> " ") Then
             ' 
    Replace all of the spaces with the specified character.
             
    strReturn Replace(strReturn" "p_strChar)
          
    End If
       
    End If
       
       
    ' Return the new string.
       MakeStringOf = strReturn
    End Function 
    Some people say 'The world is a very strange place'

    Compared to what?

  3. #3
    Join Date
    Jul 2002
    Location
    Leeds
    Posts
    123

    Enhanced mode test PHP + #

    What does ENHANCED MODE do?
    PHP Code:
    [CODE]
    ' This function makes a string of a specified number of a specified character e.g.
    a string of five dots "....." etc.
    Public Function 
    MakeStringOf(ByVal p_strChar As StringByVal p_lngCount As Long) As String
       Dim strReturn 
    As String
       
       
    ' Check that the input character is not a blank string
       ' 
    and that the length is not less than 0
       
    If (p_strChar "") Or (p_lngCount <= 0Then
          strReturn 
    ""
       
    Else
          
    ' Make a string of spaces of the specified size
          strReturn = Space(p_lngCount)
          If (p_strChar <> " ") Then
             ' 
    Replace all of the spaces with the specified character.
             
    strReturn Replace(strReturn" "p_strChar)
          
    End If
       
    End If
       
       
    ' Return the new string.
       MakeStringOf = strReturn
    End Function
    [/CODE] 
    Can anyone tell me how to get this to be VB colours rather than red comments?
    Some people say 'The world is a very strange place'

    Compared to what?

  4. #4
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588
    The only thing that works are php colors, sorry

  5. #5
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588

    Re: Colour test for VB Code

    inside a code segment...
    Code:
    ' This function makes a string of a specified length containing the specified characters. 
    This function avoides the need for loops
    Public Function MakeStringOf(ByVal p_strChar As String, ByVal p_lngCount As Long) As String
       Dim strReturn As String
       
     ' Check that the character is not blank and the length is greater than zero
       If (p_strChar = "") Or (p_lngCount <= 0) Then
          strReturn = ""
       Else
    ' Make a string of spaces of the required length
          strReturn = Space(p_lngCount)
          If (p_strChar <> " ") Then
    ' Replace the spaces in the string with the specified character
             strReturn = Replace(strReturn, " ", p_strChar)
          End If
       End If
       
       MakeStringOf = strReturn
    End Function
    Last edited by Yves M; November 1st, 2002 at 02:09 PM.

  6. #6
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588
    C++ test...

    class&nbsp;CFSM&nbsp;
    {
    public:
    &nbsp;&nbsp;typedef&nbsp;map<char,&nbsp;CFSM&nbsp;*>&nbsp;MapType;

    &nbsp;&nbsp;MapType&nbsp;&nbsp;&nbsp;&nbsp;m_map;
    &nbsp;&nbsp;set<char>&nbsp;&nbsp;&nbsp;*m_separators;

    &nbsp;&nbsp;CFSM()
    &nbsp;&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;m_separators&nbsp;=&nbsp;0;
    &nbsp;&nbsp;}

    &nbsp;&nbsp;CFSM(long&nbsp;nStrings,&nbsp;char&nbsp;**pszStr,&nbsp;set<char>&nbsp;*separators)
    &nbsp;&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;m_separators&nbsp;=&nbsp;separators;
    &nbsp;&nbsp;&nbsp;&nbsp;AddStrings(nStrings,&nbsp;pszStr);
    &nbsp;&nbsp;}

    &nbsp;&nbsp;~CFSM()
    &nbsp;&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;ClearMap();
    &nbsp;&nbsp;}

    private:
    &nbsp;&nbsp;void&nbsp;ClearMap()
    &nbsp;&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;MapType::iterator&nbsp;it;

    &nbsp;&nbsp;&nbsp;&nbsp;it&nbsp;=&nbsp;m_map.begin();
    &nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(it&nbsp;!=&nbsp;m_map.end())&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delete&nbsp;(*it).second;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_map.erase(it);
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;it&nbsp;=&nbsp;m_map.begin();
    &nbsp;&nbsp;&nbsp;&nbsp;}
    &nbsp;&nbsp;}
    public:

    &nbsp;&nbsp;void&nbsp;AddStrings(long&nbsp;nStrings,&nbsp;char&nbsp;**pszStr)
    &nbsp;&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;i,&nbsp;j,&nbsp;k;
    &nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;**pszRecStr;
    &nbsp;&nbsp;&nbsp;&nbsp;CFSM&nbsp;*recFSM;
    &nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;curr;

    &nbsp;&nbsp;&nbsp;&nbsp;i&nbsp;=&nbsp;0;
    &nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(i&nbsp;<&nbsp;nStrings)&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curr&nbsp;=&nbsp;pszStr[i][0];
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(curr&nbsp;!=&nbsp;0)&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j&nbsp;=&nbsp;i&nbsp;+&nbsp;1;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;((j&nbsp;<&nbsp;nStrings)&nbsp;&&&nbsp;(pszStr[j][0]&nbsp;==&nbsp;curr))&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j++;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pszRecStr&nbsp;=&nbsp;(char&nbsp;**)&nbsp;malloc((j&nbsp;-&nbsp;i)&nbsp;*&nbsp;sizeof(char&nbsp;*));
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(k&nbsp;=&nbsp;i;&nbsp;k&nbsp;<&nbsp;j;&nbsp;k++)&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pszRecStr[k&nbsp;-&nbsp;i]&nbsp;=&nbsp;pszStr[k]&nbsp;+&nbsp;1;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;recFSM&nbsp;=&nbsp;new&nbsp;CFSM(j&nbsp;-&nbsp;i,&nbsp;pszRecStr,&nbsp;m_separators);
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_map[curr]&nbsp;=&nbsp;recFSM;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;free(pszRecStr);
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i&nbsp;=&nbsp;j;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(m_map.find(curr)&nbsp;==&nbsp;m_map.end())&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_map[curr]&nbsp;=&nbsp;new&nbsp;CFSM;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_map[curr]->m_separators&nbsp;=&nbsp;m_separators;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i++;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
    &nbsp;&nbsp;&nbsp;&nbsp;}
    &nbsp;&nbsp;}

    &nbsp;&nbsp;void&nbsp;Traverse(int&nbsp;indent&nbsp;=&nbsp;0)
    &nbsp;&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;MapType::iterator&nbsp;it;
    &nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;i;
    &nbsp;&nbsp;&nbsp;&nbsp;bool&nbsp;bFirst&nbsp;=&nbsp;true;

    &nbsp;&nbsp;&nbsp;&nbsp;it&nbsp;=&nbsp;m_map.begin();
    &nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(it&nbsp;==&nbsp;m_map.end())&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("\n");
    &nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(it&nbsp;!=&nbsp;m_map.end())&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!bFirst)&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(i&nbsp;=&nbsp;0;&nbsp;i&nbsp;<&nbsp;indent;&nbsp;i++)&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(" ");
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("%c",&nbsp;(*it).first);
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(*it).second->Traverse(indent&nbsp;+&nbsp;1);
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bFirst&nbsp;=&nbsp;false;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;it++;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
    &nbsp;&nbsp;&nbsp;&nbsp;}
    &nbsp;&nbsp;}

    &nbsp;&nbsp;long&nbsp;IsInFSM(const&nbsp;char&nbsp;*sz)
    &nbsp;&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;MapType::iterator&nbsp;it;

    &nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(m_separators->find(sz[0])&nbsp;!=&nbsp;m_separators->end())&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;((m_map.size()&nbsp;==&nbsp;1)&nbsp;&&&nbsp;(m_map.find(0)&nbsp;!=&nbsp;m_map.end()))&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;-1;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
    &nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;((it&nbsp;=&nbsp;m_map.find(sz[0]))&nbsp;!=&nbsp;m_map.end())&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;l;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;l&nbsp;=&nbsp;(*it).second->IsInFSM(sz&nbsp;+&nbsp;1);
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(l&nbsp;==&nbsp;-1)&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;-1;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;l&nbsp;+&nbsp;1;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;-1;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
    &nbsp;&nbsp;&nbsp;&nbsp;}
    &nbsp;&nbsp;}

    };
    Last edited by Yves M; November 1st, 2002 at 01:55 PM.

  7. #7
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588
    inside a code
    Code:
    class CFSM 
    {
    public:
      typedef map<char, CFSM *> MapType;
    
      set<char>   *m_separators;
    
      CFSM(long nStrings, char **pszStr, set<char> *separators)
      {
        m_separators = separators;
        AddStrings(nStrings, pszStr);
      }
    
    private:
      void ClearMap()
      {
        MapType::iterator it;
    
        it = m_map.begin();
        while (it != m_map.end()) {
          delete (*it).second;
          m_map.erase(it);
          it = m_map.begin();
        }
      }
    public:
    
      void AddStrings(long nStrings, char **pszStr)
      {
        int i, j, k;
        char **pszRecStr;
        CFSM *recFSM;
        char curr;
    
        i = 0;
        while (i < nStrings) {
          curr = pszStr[i][0];
          if (curr != 0) {
            j = i + 1;
            while ((j < nStrings) && (pszStr[j][0] == curr)) {
              j++;
            }
            pszRecStr = (char **) malloc((j - i) * sizeof(char *));
            for (k = i; k < j; k++) {
              pszRecStr[k - i] = pszStr[k] + 1;
            }
            recFSM = new CFSM(j - i, pszRecStr, m_separators);
            m_map[curr] = recFSM;
            free(pszRecStr);
            i = j;
          } else {
            if (m_map.find(curr) == m_map.end()) {
              m_map[curr] = new CFSM;
              m_map[curr]->m_separators = m_separators;
            }
            i++;
          }
        }
      }
    
      void Traverse(int indent = 0)
      {
        MapType::iterator it;
        int i;
        bool bFirst = true;
    
        it = m_map.begin();
        if (it == m_map.end()) {
          printf("\n");
        } else {
          while (it != m_map.end()) {
            if (!bFirst) {
              for (i = 0; i < indent; i++) 
                printf(" ");
            }
            printf("%c", (*it).first);
            (*it).second->Traverse(indent + 1);
            bFirst = false;
            it++;
          }
        }
      }
    
      long IsInFSM(const char *sz)
      {
        MapType::iterator it;
    
        if (m_separators->find(sz[0]) != m_separators->end()) {
          if ((m_map.size() == 1) && (m_map.find(0) != m_map.end())) {
            return 0;
          } else {
            return -1;
          }
        } else {
          if ((it = m_map.find(sz[0])) != m_map.end()) {
            long l;
            l = (*it).second->IsInFSM(sz + 1);
            if (l == -1) {
              return -1;
            } else {
              return l + 1;
            }
          } else {
            return -1;
          }
        }
      }
    
    };

  8. #8
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588
    Code:
    char *GetClipData()
    {
      char *szRes = NULL;
    
      if (OpenClipboard(hWnd)) {
        HANDLE h;
    
        h = GetClipboardData(CF_TEXT);
        if (h) {
          char *szTmp;
        
          szTmp = (char *) GlobalLock(h);
          szRes = new char[strlen(szTmp) + 1];
          strcpy(szRes, szTmp);
          GlobalUnlock(h);
        }
        CloseClipboard();
      }
      return szRes;
    }
    Last edited by Yves M; November 1st, 2002 at 10:36 PM.

  9. #9
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588
    Great, seems to work now
    Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
    Supports C++ and VB out of the box, but can be configured for other languages.

  10. #10
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588
    Code:
    void f(float x, char *s)
    // checks something
    {
      if (x > 0) {
        printf("%s\n",s);
      } else if (x == 0) {
        printf("string's \"single &#091;COLOR=blue&#093;blue&#091;/COLOR&#093;quotes");
      } else if (x == -1) {
        /* This is not
        valid anymore */ x = 1;
      }
    }
    Last edited by Yves M; November 2nd, 2002 at 08:58 PM.
    Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
    Supports C++ and VB out of the box, but can be configured for other languages.

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

Featured