VB Visual Basic ModBus Checksum Routine

Function CRC16_BIN(ByRef ModBus_Data() As Long, NumBytes As Integer) As Long
  
    Dim Temp As Long
    Dim CRC As Long
    Dim Polynomial As Long
    Dim i As Integer
    Dim j As Integer
'—– following are read sequence checksum verification vectors  — test where either hi or lo byte == 0
'— Example temperature= 1 :   1  3  64  0  1  217  144
'—         temperature=255:   1  3  64  0  255  88  16
'—         temperature=256:   1  3  64  1  0  25  192
'—         temperature=257:   1  3  64  1  1  216  0
'—                     =0 :   1  3  64  0  0  24  80
  '— verified write string = Chr(1) & Chr(6) & Chr(64) & Chr(3) & Chr(232) & Chr(24) & Chr(34)
    CRC = 65535          '–bottom 16 bits are all 1's
    Polynomial = 40961   '–poly = A001
    For i = 0 To NumBytes – 1
      CRC = CRC Xor ModBus_Data(i)
      For j = 0 To 7
        If (CRC And 1) Then
          CRC = (ShiftRight(CRC) Xor 40961)
        Else
          CRC = ShiftRight(CRC)
        End If
      Next j
    Next i
    CRC16_BIN = CRC And 65535
   
    End Function

 

Research Links

phpBB php Bulletin Board integration into WordPress

I am researching the integration of phpBB into Wordpress.  I will put the results of my research here as time goes on.

Wp2BB

     Wp2BB Plugin Home Page   – Wp2BB in the Wordpress plugin directory  – The homepage has phpBB set up very well stylistically – It creates a forum topic automatically for every entry in your blog if you want. 

Configuration of the plugin

You have to install your phpBB separately.  Appears that it does not integrate USER / PASSWORD authentication. What that means is to log into the blog you have one user / password pair and yet another pair for the bulletin board software. 

Wp-United

 Wp-United Home Page   this site has alot of examples of its usage in well integrated artful sites. Including this one: GardeningZone.org  

Appears that the USER / PASSWORD integration problem was solved in this case.  I have not tested this but did read on their site that it is integrated.

Forum discussion of its usage

BBPress

BBPress is not phpBB. It is by the WordPress crew. For this reason I suspect it integrates more easily.

bbPress Integration – This plugin gives the default WP role to users who registered through approved bbPress installations. It also populates things like usernicename and displayname as necessary.

Notes on bbpress installation:

I found that in spite of having the most up to date version of WordPress I needed to add the following lines to my wp-config.php file

define('AUTH_KEY', 'KeyValue1');                    
define('SECURE_AUTH_KEY', 'KeyValue2');
define('LOGGED_IN_KEY', 'KeyValue3');
   AUTH_KEY, SECURE_AUTH_KEY, LOGGED_IN_KEY explanation here  HOWTO: Set up secret keys in WordPress 2.6
define('SECRET_KEY', 'KeyValue4');
    Secret Key Explanation here

The respective key values are long strings of random characters.

 Markdown for WordPress and bbPress – Markdown syntax allows you to write using an easy-to-read, easy-to-write plain text format.

punBB Latest Topics Widget

Brazil USA Dollar Exchange Rate Gyrations suggest strange times ahead

When I first went to Brazil the exchange rate was 3 reals per 1 US Dollar.  Over time the dollar had decayed to the 1.5 to 1 level.  I checked the exchange rate yesterday thinking that the rate might give some indications of the future.  I was shocked to find out that the dollar was slightly north of 2 : 1 yesterday.  Today it is 2.2 :1.  Very strange indeed.  What could the possible reasons be?

  • stealth investors have their money outside the country and there is a panic ?
  • gov't trying to stimulate economy ?
  • commodities cratering ?

This sort of gyration makes it so it is impossible to plan new business and very very difficult to maintain old business. 

Brazil USA Exchange Rate

The rate of fall of the graph is nothing short of harrowing.

Visual Basic: Returning an array from a function

How to return an array from a function

Parent Form Function that passes back an Array / Vector

 Private Sub ReceiveArray_Click()
    Dim intRcvArray() As Integer
    Dim i As Integer

    UserInterface.Text = ""
    intRcvArray = NumberList()                   ' —Get the array of strings.
   
    For i = LBound(intRcvArray) To UBound(intRcvArray)     ' —Display the strings.
       UserInterface.Text = UserInterface.Text & CStr(i) & " "
    Next i

End Sub

Private Function NumberList() As Integer()          ' — This function returns an array 
  Dim intArray() As Integer
  Dim i As Integer

    ReDim intArray(1 To 10)
    For i = 1 To 10
        intArray(i) = i             
    Next i

    NumberList = intArray
End Function

Code here: ReturnArray.zip

Visual Basic: How to pass an array parameter to another routine

This routine will pass a parameter to another routine This routine receives the call with array as parameter

 

Sub TestPassArray()

  Dim LongArray(1 To 5) As Long
  Dim i As Integer
 
  For i = 1 To 5
    LongArray(i) = i
  Next i
  
  UserDisplay.Text = CStr(PassTest(LongArray()))

End Sub                                                                                                      

 

Function PassTest(ByRef LongPass() As Long) As Long

  Dim i  As Integer
  Dim Sum As Long
 
  For i = 1 To 5
     Sum = Sum + LongPass(i)
  Next i
 
PassTest = Sum
  
End Function

 

 

  1. The passing routine packs   1,2,3,4,5 into an array.
  2. The called routine calculates the sum of all the values in the array and passes the result back to the calling routine.

Visual Basic: Saving Custom Control Persistant Properties

For more on this subject Google Search on VB Initproperties

You may wonder why we need the InitProperties event since the UserControl property already has an Initialize event in common with Class modules and other objects, such as forms.

The reason that we need InitProperties to initialize default values is that the Initialize event happens too often, that is, every time an instance or your control "wakes up." You only want the default property values to be assigned when the developers first sites a new copy of your control on a container. After that, you want the developer to be able to define persistent property values.

WARNING – Don't Use the Initialize Event to Set an ActiveX Control's Default Property Values : If you put code to initialize properties to their default values in your custom ActiveX control's Initialize event instead of in the InitProperties event, then you will have some very frustrated developers on your hands. Your default values will override the values the developer has assigned at design time every time the developer runs an application using your control.

The Property Bag is a persistent UserControl object containing the values of your control's custom, extender, and delegated properties. In fact, the Property Bag is so persistent that it doesn't get destroyed with the instances of the UserControl. This means you can store property values in the Property Bag just before an instance of the UserControl is destroyed and then retrieve the stored values when a new instance of the UserControl "wakes up" in another part of the development life cycle.

The Property Bag has two methods to store and retrieve values respectively:

  • The WriteProperty method

  • The ReadProperty method

You must know how to manipulate the Property Bag in the following situations that we discuss in the sections immediately following this one:

  • You store property values into the PropertyBag by calling its WriteProperty method in the WriteProperties event procedure.

  • You retrieve property values from the PropertyBag by calling its ReadProperty method in the ReadProperties event procedure.

  • You ensure that the WriteProperties event will fire by calling the PropertyChanged method. You'll usually do this in the Property Let procedures of your custom properties or at other appropriate places in your code where the storage value of a property changes.

—-

The operating environment fires a UserControl's ReadProperties and WriteProperties events whenever it thinks that the instantiated object's properties need to be re-initialized (ReadProperties event fires) or stored for safekeeping (WriteProperties event fires).

This arrangement makes it much easier for you, the control author, to manage these properties since you don't have to think about all the possible occasions when property values might need reading or writing. You simply need to put code for reading and writing property values in two centralized places: the ReadProperties and WriteProperties event procedures.

…………more

Visual Basic PropertyBags to remember Parameters-Its in the Bag

Recalling UserControl Properties

Standard controls have properties you can set using the object browser.  The next time you bring up your VB program for editing you need to be able to recall the state of these settings.  Example #3 on this page  shows how to use a PropertyBag to remember these settings.

 

             

  BagMan PropertyBag Example

Storage to the Bag

Save to the Bag – Fill up the object to be saved to disk Stuff it in the Bag – The actual file operation to put on disk

 Private Sub cmdSave_Click()

  Dim objBag As New PropertyBag

    With objBag
        .WriteProperty "Str", "A string"
        .WriteProperty "Num", 666
        .WriteProperty "Bool", False
        .WriteProperty "Mascot", SuperBagMan.Picture

        SaveBagContents .Contents, App.Path & "\Things.bag"
    End With
   
    Set objBag = Nothing

End Sub  

                                                                                                               

Private Sub SaveBagContents(Contents As Variant, FilePath As String)

  Dim FileNum As Integer

    FileNum = FileSystem.FreeFile()

    Open FilePath For Binary As FileNum
        Put #FileNum, , Contents
    Close FileNum

End Sub

 

 

……….more

Creative useful ideas for sellers names on ebay

One of the funniest things I ever saw on ebay was the name of the user.   They chose the following name

      AuctionOver

What is so funny about this is that when you first saw it you thought oh damnit….I missed the bidding.  Now this only worked for about 1/2 a second on me but anyone who did not look closely would just keeping clicking and skip bidding. Thus this humorous user would get better prices on that which he bought.