Public Dim

Coding + IDE + Code-Editor + Syntax + User-Functions + Anything else

Re: Public Dim

Postby berndnoetscher » Fri Nov 05, 2010 7:58 am

Hi Henning,

as I would love to see your app working, why don't you send me your project files to me again. The latest you already did using Qt designer to create your GUI.
I will do the conversion for you for some comments in code to help you to understand the conversion.
What do you think?

CU
Bernd

Henning wrote:Hi

I have partly solved it the "easy" way. By replacing the Typename.Member with Typename_member.

The original
Code: Select all
Public Dim TxMsg[17] As Byte
Type T_Msg
  Type As Byte
  ID As Short
  tSYSTEM As Byte
  unit As Byte
  port As Byte
  data(7) As Byte
  ReplyTo As Short
  crc As Short
End Type
'
Type U_SetupMsg
  Type As Byte
  UType As Byte
  UCh As Byte
  USys As Byte
  Uunit As Byte
  UPwr As Byte
  USpc As Byte
  USpc2 As Byte
  USpc3 As Byte
  ReplyTo As Short
  crc As Short
End Type

Type Shadow
  data(8) As Byte
End Type

Public TMsg As T_Msg
Public UTMsg As U_SetupMsg
Public TCmd As T_Msg
Public AckMsg As T_Msg
Public BS As T_Msg
Public InShadow[254] As Shadow
Public UtShadow[254] As Shadow

'Later in a sub next problem arises, TxMsg() is a Byte Array to send as UDP
  TxMsg[0] = TCmd.Type  ' 1
  TxMsg[1] = TCmd.ID \ 256 'Asc("C")
  TxMsg[2] = TCmd.ID And &HFF ' 0
  TxMsg[3] = TCmd.tSYSTEM
  TxMsg[4] = TCmd.unit
  TxMsg[5] = TCmd.port
  TxMsg[6] = TCmd.data[7]
  TxMsg[7] = TCmd.data[6]
  TxMsg[8] = TCmd.data[5]
  TxMsg[9] = TCmd.data[4]
  TxMsg[10] = TCmd.data[3]
  TxMsg[11] = TCmd.data[2]
  TxMsg[12] = TCmd.data[1]
  TxMsg[13] = TCmd.data[0]
  TxMsg[14] = TCmd.ReplyTo \ 256
  TxMsg[15] = TCmd.ReplyTo And &HFF
  CRCTx = 0
  For i = 0 To 15      'Calculate CRC
    CRCTx = CRCTx + TxMsg[i]
  Next
  TCmd.crc = CRCTx
  TxMsg[16] = TCmd.crc \ 256
  TxMsg[17] = TCmd.crc And &HFF
  'TxMsg(7) = crcTx And &HFF


'New' version, TxMsg() could be a String (if Mid$() is working?)
Code: Select all
Public Dim TMsg_Type As Integer
Public Dim TMsg_ID As Integer
Public Dim TMsg_tSYSTEM As Integer
Public Dim TMsg_unit As Integer
Public Dim TMsg_port As Integer
Public Dim TMsg_data[7] As Integer
Public Dim TMsg_ReplyTo As Integer
Public Dim TMsg_crc As Integer
'
Public Dim TCmd_Type As Integer
Public Dim TCmd_ID As Integer
Public Dim TCmd_tSYSTEM As Integer
Public Dim TCmd_unit As Integer
Public Dim TCmd_port As Integer
Public Dim TCmd_data[7] As Integer
Public Dim TCmd_ReplyTo As Integer
Public Dim TCmd_crc As Integer

Public Dim AckMsg_Type As Integer
Public Dim AckMsg_ID As Integer
Public Dim AckMsg_tSYSTEM As Integer
Public Dim AckMsg_unit As Integer
Public Dim AckMsg_port As Integer
Public Dim AckMsg_data[7] As Integer
Public Dim AckMsg_ReplyTo As Integer
Public Dim AckMsg_crc As Integer

Public Dim BS_Type As Integer
Public Dim BS_ID As Integer
Public Dim BS_tSYSTEM As Integer
Public Dim BS_unit As Integer
Public Dim BS_port As Integer
Public Dim BS_data[7] As Integer
Public Dim BS_ReplyTo As Integer
Public Dim BS_crc As Integer


Public Dim UTMsg_Type As Integer
Public Dim UTMsg_UType As Integer
Public Dim UTMsg_UCh As Integer
Public Dim UTMsg_USys As Integer
Public Dim UTMsg_Uunit As Integer
Public Dim UTMsg_UPwr As Integer
Public Dim UTMsg_USpc As Integer
Public Dim UTMsg_USpc2 As Integer
Public Dim UTMsg_USpc3 As Integer
Public Dim UTMsg_ReplyTo As Integer
Public Dim UTMsg_crc As Integer
'
'Type Shadow
Public Dim Shadow_data(8) As Integer
'End Type
'
'*Public TMsg As T_Msg
'*Public UTMsg As U_SetupMsg
'*Public TCmd As T_Msg
'*Public AckMsg As T_Msg
'*Public BS As T_Msg
Public Dim InShadow[254] As Shadow_data
Public Dim UtShadow[254] As Shadow_data

'In same sub as above
  TxMsg[0] = TCmd_Type  ' 1
  TxMsg[1] = TCmd_ID \ 256 'Asc("C")
  TxMsg[2] = TCmd_ID And &HFF ' 0
  TxMsg[3] = TCmd_tSYSTEM
  TxMsg[4] = TCmd_unit
  TxMsg[5] = TCmd_port
  TxMsg[6] = TCmd_data[7]
  TxMsg[7] = TCmd_data[6]
  TxMsg[8] = TCmd_data[5]
  TxMsg[9] = TCmd_data[4]
  TxMsg[10] = TCmd_data[3]
  TxMsg[11] = TCmd_data[2]
  TxMsg[12] = TCmd_data[1]
  TxMsg[13] = TCmd_data[0]
  TxMsg[14] = TCmd_ReplyTo \ 256
  TxMsg[15] = TCmd_ReplyTo And &HFF
  CRCTx = 0
  For i = 0 To 15      'Calculate CRC
    CRCTx = CRCTx + TxMsg[i]
  Next
  TCmd_crc = CRCTx
  TxMsg[16] = TCmd_crc \ 256
  TxMsg[17] = TCmd_crc And &HFF

'I will try Public Dim TxMsg As String * 18
Mid$(TxMsg,1,1) = Chr$(TCmd_Type And &HFF) ' Here comes the (self-documenting) Hex values again. Or what replaces Mid$.


/Henning
berndnoetscher
Site Admin
 
Posts: 344
Joined: Thu Mar 25, 2010 9:57 am

Re: Public Dim

Postby tseyfarth » Sat Nov 27, 2010 4:36 am

Is there a particular location where all Public Vars should go? What is best practice for this?

TY
Tim
tseyfarth
 
Posts: 67
Joined: Mon Oct 18, 2010 12:37 am

Re: Public Dim

Postby Henning » Sat Nov 27, 2010 5:44 pm

If declared in Global.QObject as Public Dim anyvar As sometype, it is accesable everywhere.

If declared in i.e. a MyModule.QObject we have to access it as MyModule.anyvar.

B has said to add Global to be able to declare public vars in any module, without the need of module.var.

/Henning
Henning
 
Posts: 523
Joined: Fri Aug 13, 2010 6:29 pm

Re: Public Dim

Postby tseyfarth » Sat Nov 27, 2010 6:22 pm

OK, so it is similar to VB6 where Publics had to be declared in Modules, not forms. This is OK with me. I personally like all publics to be in one place so the Global.QObject works for me.

I wonder if they are superseded in Forms or otherwise outside of the Global.QObject.

Thank you again!
Tim
tseyfarth
 
Posts: 67
Joined: Mon Oct 18, 2010 12:37 am

Re: Public Dim

Postby Henning » Sat Nov 27, 2010 8:49 pm

Well, even in VB we need to address Form Public variables with FomName.varname.

I use to have some 4-5 Modules, where each has subs, functions and public const/varibles that belong to the same task. So for me Global is a very usable addition.

/Henning
Henning
 
Posts: 523
Joined: Fri Aug 13, 2010 6:29 pm

Re: Public Dim

Postby tseyfarth » Sun Nov 28, 2010 12:11 am

Yes, I did too, for a while. I always make vars public (global) that are used across several subs or functions. I group them together in one place for easier reference.

Tim
tseyfarth
 
Posts: 67
Joined: Mon Oct 18, 2010 12:37 am

Re: Public Dim

Postby berndnoetscher » Mon Nov 29, 2010 1:13 pm

tseyfarth wrote:OK, so it is similar to VB6 where Publics had to be declared in Modules, not forms. This is OK with me. I personally like all publics to be in one place so the Global.QObject works for me.

I wonder if they are superseded in Forms or otherwise outside of the Global.QObject.

Thank you again!
Tim



FomName.varname is expected to work already, which are globally accessable.
berndnoetscher
Site Admin
 
Posts: 344
Joined: Thu Mar 25, 2010 9:57 am

Previous

Return to Questions & Answers

Who is online

Users browsing this forum: No registered users and 1 guest

cron